Aug-26-2021, 05:24 PM
(This post was last modified: Aug-26-2021, 05:25 PM by deanhystad.)
naughtyCat, your letter grade code does not work.:
You could do this:
This is better, but still frowned upon.
average = [95] for item in average: if item > 90: print(f"{item}: grade A") if item > 80: print(f"{item}: grade B") if item > 70: print(f"{item}: grade C") else: print(f"{item}: grade F")
Output:95: grade A
95: grade B
95: grade C
I thought the output looked odd and realized there were more grades reported in the output than there were grades in the score lists.You could do this:
for item in average: if item > 90: print(f"{item}: grade A"); continue if item > 80: print(f"{item}: grade B"); continue if item > 70: print(f"{item}: grade C"); continue print(f"{item}: grade F")But that having multiple statements on one line is frowned upon.
This is better, but still frowned upon.
for item in average: if item > 90: print(f"{item}: grade A") # Still multiple statements on one line elif item > 80: print(f"{item}: grade B") elif item > 70: print(f"{item}: grade C") else: print(f"{item}: grade F")