-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistration_app.py
More file actions
71 lines (56 loc) · 2.35 KB
/
registration_app.py
File metadata and controls
71 lines (56 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
student_list = []
def create_student():
#Ask user for the student name and marks
student_name = input("Enter your name: ")
# create a dict in the format {'name':student_name, 'marks': []}
student = {'name':student_name,
'marks': []}
# return the dictionary
return student
def add_marks(student, mark):
#add a mark to the student dictionary
student["marks"].append(mark)
def calc_avg_mark(student):
#check len of students marks
number = len(student['marks'])
if number == 0:
return 0
#calculate the average
total = sum(student['marks'])
return total/number
def student_details(student):
#print out the string that tells the user the info abouth the student
print(f"The name of the student is {student['name']}, scores are {student['marks']}"
f" and the average mark is {calc_avg_mark(student)}")
def print_all_students(students):
# print out the string that tells the user the info abouth the student for every student in the list
for i, student in enumerate(students):
print(f"ID : {i}")
print(student_details(student))
def menu():
#add a student to a student list
#add a mark to a student
#Print a list of students
#Exit the application
selection = input("Enter 'p' to print the list of all students,"
" 's' to add a new student,"
" 'm' to add marks for the student,"
" 'q' to exit"
"\nEnter your selection: ...")
while selection != 'q':
if selection == 'p':
print_all_students(student_list)
print("No students in the list")
elif selection == 's':
student_list.append(create_student())
elif selection == 'm':
student_id = int(input("Enter the student ID to a mark to: "))
student = student_list[student_id]
new_mark = int(input("Enter a new mark to be added: "))
add_marks(student, new_mark)
selection = input("Enter 'p' to print the list of all students,"
" 's' to add a new student,"
" 'm' to add marks for the student,"
" 'q' to exit"
"\nEnter your selection: ...")
menu()