Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def take_info(database):
- while True:
- c = input("Do you want to enter student info (y/n): ")
- if c == "n":
- break
- elif c == "y":
- name = input("Enter the student name: ")
- mid1 = int(input("Enter midterm 1 grade: "))
- mid2 = int(input("Enter midterm 2 grade: "))
- final = int(input("Enter final exam grade: "))
- student = {"name":name, "midterm_1":mid1, "midterm_2":mid2, "final":final}
- database.append(student)
- def print_info(database):
- n = input("Enter student name: ")
- names = []
- for student in database:
- names.append(student["name"])
- if n not in names:
- print(f'No info for {n}')
- else:
- print(database[names.index(n)])
- def print_stat(database):
- midterm_1 = []
- midterm_2 = []
- final = []
- for student in database:
- midterm_1.append(student["midterm_1"])
- midterm_2.append(student["midterm_2"])
- final.append(student["final"])
- if len(midterm_1)>0:
- print(f"midterm_1: max= {max(midterm_1)}, min= {min(midterm_1)}, avg= {sum(midterm_1)/len(midterm_1)}.")
- print(f"midterm_2: max= {max(midterm_2)}, min= {min(midterm_2)}, avg= {sum(midterm_2) / len(midterm_2)}.")
- print(f"final: max= {max(final)}, min= {min(final)}, avg= {round(sum(final) / len(final)),2}.")
- database = []
- while True:
- print('''0. Exit
- 1. Enter student info
- 2. Print grades for a student
- 3. Print class max, min, and average grades''')
- choice = input("Enter your choice: ")
- if choice == "0":
- exit()
- elif choice == "1":
- take_info(database)
- elif choice == "2":
- print_info(database)
- elif choice == "3":
- print_stat(database)
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement