def compute_average_grade(): #Get user input name = input("Name: ") math_grade = float(input("Math: ")) science_grade = float(input("Science: ")) english_grade = float(input("English: ")) #Calculate average average = (math_grade + science_grade + english_grade) / 3 #Determine status if average >= 75: status = "Passed" message = "Congrats! You passed the semester." if average >= 75 and english_grade < 75: message += f" But you need to re-enroll in the English subject." elif average >= 75 and science_grade < 75: message += f" But you need to re-enroll in the Science subject." elif average >= 75 and math_grade < 75: message += f" But you need to re-enroll in the Math subject." else: status = "Failed" message = "You failed the semester." #Display results print(f"\nAverage: {average:.1f}") print(f"{message}") #Run the program compute_average_grade()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter