Jun-04-2020, 03:07 AM
Since most of the print is the same except for the letter, let's just set the letter.
Also, if you don't take the first branch, you know you can't be 86 or higher, so you don't have to test for it. Combining those two elements might give you this:
Also, if you don't take the first branch, you know you can't be 86 or higher, so you don't have to test for it. Combining those two elements might give you this:
letter_grade = "Unknown" if total_sum >= 86: letter_grade = "A" elif total_sum>=74: letter_grade = "B" elif total_sum >=62: letter_grade = "C" elif total_sum >=54: letter_grade = "D" else: letter_grade = "F" print(f"You received a {letter_grade} with a total score of {total_sum}")This doesn't keep the "failed the course" sentence, but it would be easy to add that back with another if/then.
if total_sum >= 54: print(f"normal message about {letter_grade} and {total_score}") else: print("You failed the course")