Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- admins = {'Pete':'123','John':'321'}
- usernameInput = ''
- passInput = ''
- gradesDict = {'Pete':[1,2,3],'John':[9,8,7],'Johny':[]}
- from statistics import *
- #Check if the student name exists as key in the dictionary
- def studentExists(name):
- flag = False
- if name in gradesDict:
- flag = True
- return flag
- #Adding the student key and grade to the dictionary
- def addStudent(name, grade):
- gradesDict[name] = [grade]
- print('\nUpdated list: ',gradesDict)
- #Adding the already existing student grade to the dictionary
- def addGrade(name, grade):
- gradesDict[name].append(grade)
- print('\nUpdated list: ',gradesDict)
- #Passing the name of the student we want to remove from the main script
- def removeStudent(name):
- del gradesDict[name]
- print('\nRemoving student: ',name)
- print('\nUpdated list: ',gradesDict)
- def getAverage(name):
- print('\n'+name,'average grade is:',mean(gradesDict[name]))
- def getAverageAll():
- for student in gradesDict:
- try:
- gradeList = gradesDict[student]
- print(student,'average grade is:',mean(gradesDict[student]))
- except StatisticsError as se:
- print(student,'average grades cannot be calculated!')
- #MAIN PROGRAM
- while usernameInput not in admins or admins[usernameInput]!=passInput:
- usernameInput = input('Username:')
- passInput = input('Password:')
- if usernameInput not in admins or admins[usernameInput]!=passInput:
- print('\nPlease provide valid username and password!\n')
- print('\nWelcome to the Grading Centre')
- while True:
- try:
- menuInput = input("""
- [1] - Enter Grades
- [2] - Remove Student
- [3] - Calculate Average Grade of student
- [4] - Get Average Grade for each student
- [5] - Exit
- What would you like to do today? [Enter a number from the menu]: """)
- menuInput = int(menuInput)
- except Exception as e:
- print(e)
- if menuInput == 1:
- name = ''
- grade = -1
- name = input('\nStudent Name: ')
- while grade <0 or grade >100:
- try:
- grade = input('Student Grade: ')
- grade = float(grade)
- if(grade<0 or grade >100):
- print('\nEnter grade between 0 and 100!\n')
- except Exception as e:
- print('\nPlease enter valid grade!\n')
- grade = -1
- if studentExists(name):
- addGrade(name, grade)
- else:
- add = input('\nThe student you have entered does not exist, please confirm if you want to add a new Student? [Y/N]\n')
- add = add.upper()
- if add == 'Y':
- addStudent(name, grade)
- elif menuInput == 2:
- print('Student list: ',gradesDict,'\n')
- print('Please enter a student name from the list or type \'q\' to go back to the menu!')
- name = ''
- count = 0
- while not(studentExists(name)) and name.lower() != 'q':
- if count > 0:
- print('\nPlease enter valid student name!')
- name = input('\nStudent Name: ')
- count+=1
- if studentExists(name):
- removeStudent(name)
- elif menuInput == 3:
- print('Student list: ',gradesDict,'\n')
- print('Please enter a student name from the list or type \'q\' to go back to the menu!')
- name = ''
- count = 0
- while not(studentExists(name)) and name.lower() != 'q':
- name = input('\nStudent Name: ')
- if not(studentExists(name)):
- print('\nPlease enter valid student name or press \'q\'!')
- if studentExists(name):
- try:
- getAverage(name)
- except StatisticsError as e:
- name = ''
- print('\nThe student you have entered has no grades!')
- elif menuInput == 4:
- getAverageAll()
- elif menuInput == 5:
- exit()
- else:
- print('\nPlease enter a valid option from the menu!\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement