import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
print('++++++++++++++++++ CSKM Public School +++++++++++++')
print(' Welcome to Result Module ')
print('-------------Select the correct choice to work on Result Module-------')
option = 1
dfresult=pd.read_csv('result.csv',
header=None,
names=['SchNo','Name','sub1','sub2','sub3','sub4','sub5'])
while (option != 6):
print()
print('1. Add a new result')
print('2. Update Result')
print('3. Delete Result')
print('4. View Result')
print('5. View Chart')
print('6. Exit Result Module')
option = int(input('Enter Choice : '))
#Code for addition
if (option == 1):
# Take details of the students
schoolNo = int(input('Enter School Number : '))
name = input('Enter Name : ')
sub1 = int(input('Enter Marks of Subject-1 : '))
sub2 = int(input('Enter Marks of Subject-2 : '))
sub3 = int(input('Enter Marks of Subject-3 : '))
sub4 = int(input('Enter Marks of Subject-4 : '))
sub5 = int(input('Enter Marks of Subject-5 : '))
# Code to add data to dataframe
# and write the updated dataframe to csv file
totalResult = dfresult['SchNo'].count()
dfresult.loc[totalResult] = [schoolNo,name,sub1,sub2,sub3,sub4,sub5]
print('--------------OUTPUT-----------------')
print('Result Added....')
dfresult.to_csv('result.csv',header=False,index=False)
print(dfresult)
print('-------------------------------------')
# Code for updation
elif (option == 2):
# Search Record with school number
schoolNo = int(input('Enter School Number : '))
indexno = dfresult.loc[dfresult['SchNo'] == schoolNo].index
print(dfresult.loc[dfresult['SchNo'] == schoolNo])
print('What would you like to change?')
print('1. To Change School Number')
print('2. To Change Name')
print('3. To Change Marks of Subject-1')
print('4. To Change Marks of Subject-2')
print('5. To Change Marks of Subject-3')
print('6. To Change Marks of Subject-4')
print('7. To Change Marks of Subject-5')
print('8. Back to main menu')
changeoption = int(input('What would you like to change? : '))
# Code to change the Data as per input choice
if (changeoption == 1):
schoolNoNew = int(input('Enter New School Number : '))
dfresult.loc[indexno,'SchNo'] = schoolNoNew
dfresult.to_csv('result.csv',header=False,index=False)
elif (changeoption == 2):
nameNew = input('Enter New Name : ')
dfresult.loc[indexno,'Name'] = nameNew
dfresult.to_csv('result.csv',header=False,index=False)
elif (changeoption == 3):
sub1New = input('Enter New Marks for Subject-1 : ')
dfresult.loc[indexno,'sub1'] = sub1New
dfresult.to_csv('result.csv',header=False,index=False)
elif (changeoption == 4):
sub2New = input('Enter New Marks for Subject-2 : ')
dfresult.loc[indexno,'sub2'] = sub2New
dfresult.to_csv('result.csv',header=False,index=False)
elif (changeoption == 5):
sub3New = input('Enter New Marks for Subject-3 : ')
dfresult.loc[indexno,'sub3'] = sub3New
dfresult.to_csv('result.csv',header=False,index=False)
elif (changeoption == 6):
sub4New = input('Enter New Marks for Subject-4 : ')
dfresult.loc[indexno,'sub4'] = sub4New
dfresult.to_csv('result.csv',header=False,index=False)
elif (changeoption == 7):
sub5New = input('Enter New Marks for Subject-5 : ')
dfresult.loc[indexno,'sub5'] = sub5New
dfresult.to_csv('result.csv',header=False,index=False)
print('Record Updated....')
print(dfresult.loc[dfresult['SchNo'] == schoolNo])
print('-----------------------------------')
#Code for deletion
elif (option ==3):
# Search Record with school number
schoolNo = int(input('Enter School Number : '))
indexno = dfresult.loc[dfresult['SchNo'] == schoolNo].index
print('--------------OUTPUT-----------------')
print(dfresult.loc[dfresult['SchNo'] == schoolNo])
deleteconfirm = input('Are You Sure You Want To Delete Record? (Y/N) : ')
# Code to change the Data as per input choice
if (deleteconfirm == 'Y' or deleteconfirm == 'y'):
dfresult = dfresult.drop(indexno)
print('Record Deleted....')
dfresult.to_csv('result.csv',header=False,index=False)
print('--------------------------------------')
#Code for vieweing records
elif (option ==4):
print('1. Display on the basis of school number')
print('2. Display on the basis of name')
print('3. Display on the basis of subject1')
print('4. Display on the basis of subject2')
print('5. Display on the basis of subject3')
print('6. Display on the basis of subject4')
print('7. Display on the basis of subject5')
print('8. Display all records')
print('9. Display top ___ records')
print('10. Display bottom ___ records')
print('11. Back to main menu')
displaychoice = int(input('Enter your choice : '))
print('--------------OUTPUT-----------------')
if (displaychoice == 1):
schoolNoDisplay = int(input('Enter School Number : '))
print(dfresult.loc[dfresult['SchNo'] == schoolNoDisplay])
elif (displaychoice == 2):
nameDisplay = input('Enter Name to Search : ')
print(dfresult.loc[dfresult['Name'] == nameDisplay])
elif (displaychoice == 3 or
displaychoice == 4 or
displaychoice == 5 or
displaychoice == 6 or
displaychoice == 7):
print('1. More Than')
print('2. More Than and Equal To')
print('3. Less Than')
print('4. Less Than and Equal To')
print('5. Equal To')
print('6. Not Equal To')
condition = int(input('Enter your choice for condition : '))
marks = int(input('Enter Marks : '))
if (condition == 1):
if (displaychoice == 3):
print(dfresult.loc[dfresult['sub1'] > marks])
elif (displaychoice == 4):
print(dfresult.loc[dfresult['sub2'] > marks])
elif (displaychoice == 5):
print(dfresult.loc[dfresult['sub3'] > marks])
elif (displaychoice == 6):
print(dfresult.loc[dfresult['sub4'] > marks])
elif (displaychoice == 7):
print(dfresult.loc[dfresult['sub5'] > marks])
elif (condition == 2):
if (displaychoice == 3):
print(dfresult.loc[dfresult['sub1'] >= marks])
elif (displaychoice == 4):
print(dfresult.loc[dfresult['sub2'] >= marks])
elif (displaychoice == 5):
print(dfresult.loc[dfresult['sub3'] >= marks])
elif (displaychoice == 6):
print(dfresult.loc[dfresult['sub4'] >= marks])
elif (displaychoice == 7):
print(dfresult.loc[dfresult['sub5'] >= marks])
elif (condition == 3):
if (displaychoice == 3):
print(dfresult.loc[dfresult['sub1'] < marks])
elif (displaychoice == 4):
print(dfresult.loc[dfresult['sub2'] < marks])
elif (displaychoice == 5):
print(dfresult.loc[dfresult['sub3'] < marks])
elif (displaychoice == 6):
print(dfresult.loc[dfresult['sub4'] < marks])
elif (displaychoice == 7):
print(dfresult.loc[dfresult['sub5'] < marks])
elif (condition == 4):
if (displaychoice == 3):
print(dfresult.loc[dfresult['sub1'] <= marks])
elif (displaychoice == 4):
print(dfresult.loc[dfresult['sub2'] <= marks])
elif (displaychoice == 5):
print(dfresult.loc[dfresult['sub3'] <= marks])
elif (displaychoice == 6):
print(dfresult.loc[dfresult['sub4'] <= marks])
elif (displaychoice == 7):
print(dfresult.loc[dfresult['sub5'] <= marks])
elif (condition == 5):
if (displaychoice == 3):
print(dfresult.loc[dfresult['sub1'] == marks])
elif (displaychoice == 4):
print(dfresult.loc[dfresult['sub2'] == marks])
elif (displaychoice == 5):
print(dfresult.loc[dfresult['sub3'] == marks])
elif (displaychoice == 6):
print(dfresult.loc[dfresult['sub4'] == marks])
elif (displaychoice == 7):
print(dfresult.loc[dfresult['sub5'] == marks])
elif (condition != 6):
if (displaychoice != 3):
print(dfresult.loc[dfresult['sub1'] != marks])
elif (displaychoice != 4):
print(dfresult.loc[dfresult['sub2'] != marks])
elif (displaychoice != 5):
print(dfresult.loc[dfresult['sub3'] != marks])
elif (displaychoice != 6):
print(dfresult.loc[dfresult['sub4'] != marks])
elif (displaychoice != 7):
print(dfresult.loc[dfresult['sub5'] != marks])
elif (displaychoice == 8):
print(dfresult)
elif (displaychoice == 9):
toprecords = int(input('Enter The Top Number of Records to Display : '))
print(dfresult.head(toprecords))
elif (displaychoice == 10):
bottomrecords = int(input('Enter The Bottom Number of Records to
Display : '))
print(dfresult.tail(bottomrecords))
print('--------------------------------------')
#Code to display line chart
elif (option ==5):
print('1. Display subject wise Average Bar chart')
print('2. Display student wise percent Bar chart')
print('3. Back to main menu')
chartoption = int(input('Enter your choice : '))
#Display Class wise number of students
if (chartoption == 1):
subjects = ['sub1','sub2','sub3','sub4','sub5']
subavg = dfresult[subjects].mean(axis=0).values
plt.bar(subjects,subavg)
plt.xlabel('Subject')
plt.ylabel('Average Marks')
plt.title('Subject Wise Average Marks')
plt.show()
#Display Section wise number of students
elif (chartoption == 2):
names = dfresult['Name'].to_list()
percent = dfresult.mean(axis=1).values
plt.bar(names,percent)
plt.xlabel('Students')
plt.ylabel('Percentage')
plt.title('Student Wise Percentage')
plt.show()
print('------------Thanks for using Result Module----------')