MeckeOfficial

grades

Sep 28th, 2021 (edited)
662
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # while Loop to get 4 Subjects, if the User enters more than 4 or less than 4
  2. # ask User again for Input
  3. while True:
  4.    
  5.     # with the split() at the End of the Input we can convert the Input to a list,
  6.     # containing the Subjects seperated by semi-colon
  7.     subjects = input("Please enter 4 Subjects, seperated by semi-colon (;): ").split(";")
  8.  
  9.     # if the User entered 4 Subjects we can break the Loop
  10.     if len(subjects) == 4:
  11.         break
  12.  
  13.     # If the user enters the wrong amount of Subjects we will let him know and ask again for Input
  14.     else:
  15.         print("You have entered more or less than 4 Subjects.")
  16.  
  17. # same Loop as above to get the 4 Grades of the User
  18. while True:
  19.  
  20.     # same split as we did on the Subjects
  21.     grades = input("Enter grades of the Subjects seperated by comma (,): ").split(",")
  22.  
  23.     if len(grades) == 4:
  24.         # here we try to convert the Grades to Integers,
  25.         # responds with an Error if the User enters Strings instead of Numbers
  26.         try:
  27.             grades = [int(grade) for grade in grades]
  28.             break
  29.         # Printing an Error if User gave wrong input
  30.         except ValueError:
  31.             print("You had a wrong Input, please reenter the Grades.")
  32.  
  33.     else:
  34.         print("You have entered more or less than 4 Grades.")
  35.  
  36. # getting the Average by Add all grades together and divide them by the length of the List
  37. avg_grade = sum(grades)/len(grades)
  38.  
  39. # creating an empty list for all Subjects we need to retake
  40. retake = []
  41.  
  42. # loop through all Grades
  43. for x in range(len(subjects)):
  44.  
  45.     # if the Grade is below 75 we add the Subject to our Retake-List
  46.     if grades[x] < 75:
  47.         retake.append(subjects[x])
  48.  
  49.     # printing the Grade for the Subject
  50.     print(f"Grade in {subjects[x]} = {grades[x]}")
  51.  
  52. # printing the average Grade, rounded to 2 decimals
  53. print(f"Average Grade: {avg_grade:.2f}")
  54.  
  55. # if the Average is above 75 the User passed the Test
  56. if avg_grade >= 75:
  57.     print("Remarks: Passed")
  58. else:
  59.     print("Remarks: Failed")
  60.  
  61. # if we have added any Subjects to the Retake-List,
  62. # we let the User know what Subjects he has to redo
  63. if len(retake) > 0:
  64.     print("Notes: Subjects need to retake: ")
  65.     for r in retake:
  66.         print(r)
  67.  
  68. # if the User passed all Subjects, we can congratulate him
  69. else:
  70.     print("Well done! no Subjects needed to be retaken.")
  71.  
RAW Paste Data