You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
grade tracking program - think through the goal up front- what is the task and design?
3
+
needs to enable several basic functions for teachers
4
+
needs to have login to protect the student data
5
+
'''
6
+
#import libraries first
7
+
importstatisticsass
8
+
9
+
#add constants next
10
+
admins= {'Faculty1':'ABC123','Faculty2':'ABC123'}
11
+
12
+
#Like the admins above is a dictionary but of students. Dictionaries use curly brackets with colons to associate keys with values. In this case, each student's first name is a key. The values are lists of grades.
13
+
#Lists are denoted with square brackets. Values are indexed within starting with 0 for the first one. Each value is separated by commas.
14
+
students= {'Alex':[87,88,98],
15
+
'Sally':[88,67,93],
16
+
'Nboke':[90,88,78]}
17
+
18
+
#Now we define functions. Functions encapsulate logic into reusable recipes that can be executed whenever we need them by calling their name with parentheses.
19
+
defenterGrades():
20
+
nameToEnter=input('Student name: ')
21
+
gradeToEnter=input('Grade: ')
22
+
#This checks through the keys of the students dictionary to see if the name entered exactly matches any one in there.
23
+
ifnameToEnterinstudents:
24
+
print('Adding grade for'+nameToEnter)
25
+
students[nameToEnter].append(float(gradeToEnter)) #float will have a .0
26
+
print(str(nameToEnter)+' now has these grades:')
27
+
print(students[nameToEnter])
28
+
else:
29
+
print('Student not found. Please check your spelling or go back and add if new.')
30
+
31
+
defremoveStudent():
32
+
nameToRemove=input('Who do you want to remove? ')
33
+
ifnameToRemoveinstudents:
34
+
print('Removing '+nameToRemove)
35
+
delstudents[nameToRemove]
36
+
print(students)
37
+
else:
38
+
print('Student not found.')
39
+
40
+
defaverageStudents():
41
+
forstudentinstudents:
42
+
grades=students[student]
43
+
average=s.mean(grades) #notice the s? we imported the statistuics module as s. Thus, we are using a fucntion called "mean()" from the statistics module.
44
+
print(student,' average ',average)
45
+
46
+
defmain():
47
+
print("User: "+login)
48
+
#Here we present our main menu options once a person logs in successfully.
49
+
print("""
50
+
Welcome to the Grade Tracker
51
+
52
+
[1] - Enter Grades
53
+
[2] - Remove Student
54
+
[3] - Student Averages
55
+
[4] - Exit
56
+
""")
57
+
58
+
action=input('What would you like to do? (Enter a number) ')
59
+
#Here we process their choice of what they want to do.
60
+
ifaction=='1':
61
+
#print('1 selected')
62
+
enterGrades()
63
+
elifaction=='2':
64
+
#print('2 selected')
65
+
removeStudent()
66
+
elifaction=='3':
67
+
#print('3 selected')
68
+
averageStudents()
69
+
elifaction=='4':
70
+
#print('4 selected')
71
+
exit()
72
+
else:
73
+
print('Valid option not selected.') #need to cause it to reprompt
0 commit comments