Advertisement
biswasrohit20

data

Apr 25th, 2021
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. def take_info(database):
  2. while True:
  3. c = input("Do you want to enter student info (y/n): ")
  4. if c == "n":
  5. break
  6. elif c == "y":
  7. name = input("Enter the student name: ")
  8. mid1 = int(input("Enter midterm 1 grade: "))
  9. mid2 = int(input("Enter midterm 2 grade: "))
  10. final = int(input("Enter final exam grade: "))
  11. student = {"name":name, "midterm_1":mid1, "midterm_2":mid2, "final":final}
  12. database.append(student)
  13.  
  14.  
  15. def print_info(database):
  16. n = input("Enter student name: ")
  17. names = []
  18. for student in database:
  19. names.append(student["name"])
  20. if n not in names:
  21. print(f'No info for {n}')
  22. else:
  23. print(database[names.index(n)])
  24.  
  25.  
  26.  
  27. def print_stat(database):
  28. midterm_1 = []
  29. midterm_2 = []
  30. final = []
  31. for student in database:
  32. midterm_1.append(student["midterm_1"])
  33. midterm_2.append(student["midterm_2"])
  34. final.append(student["final"])
  35. if len(midterm_1)>0:
  36. print(f"midterm_1: max= {max(midterm_1)}, min= {min(midterm_1)}, avg= {sum(midterm_1)/len(midterm_1)}.")
  37. print(f"midterm_2: max= {max(midterm_2)}, min= {min(midterm_2)}, avg= {sum(midterm_2) / len(midterm_2)}.")
  38. print(f"final: max= {max(final)}, min= {min(final)}, avg= {round(sum(final) / len(final)),2}.")
  39.  
  40.  
  41. database = []
  42. while True:
  43. print('''0. Exit
  44. 1. Enter student info
  45. 2. Print grades for a student
  46. 3. Print class max, min, and average grades''')
  47. choice = input("Enter your choice: ")
  48. if choice == "0":
  49. exit()
  50. elif choice == "1":
  51. take_info(database)
  52. elif choice == "2":
  53. print_info(database)
  54. elif choice == "3":
  55. print_stat(database)
  56. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement