1.Marks to grades
BeginnerFor each mark in marks = [95, 82, 67, 45, 74], print the mark and its grade:
- 90 and above:
A - 75 to 89:
B - 60 to 74:
C - below 60:
F
Show hint
Use if / elif / else and check from the highest grade down, so each check only needs a lower limit.
Show solution
marks = [95, 82, 67, 45, 74]
for mark in marks:
if mark >= 90:
grade = "A"
elif mark >= 75:
grade = "B"
elif mark >= 60:
grade = "C"
else:
grade = "F"
print(mark, grade)95 A
82 B
67 C
45 F
74 CBecause elif branches are checked in order and only the first true one runs, elif mark >= 75 already knows the mark is below 90.