Grade program

The program is given in exercise as correct one.
grade = 86

if grade >= 90:
print(“A”)
elif grade < 90 and grade >= 80:
print(“B”)
elif grade < 80 and grade >= 70:
print(“C”)
elif grade < 70 and grade >= 60:
print(“D”)
else:
print(“F”)

But if grade is 86, logically it matches all the grades.

Shouldn’t the program be like this

grade = 86

if grade >= 90:
print(“A”)
elif grade < 90 and grade >= 80:
print(“B”)
elif grade < 80 and grade >= 70:
print(“C”)
elif grade < 70 and grade >= 60:
print(“D”)
else:
print(“F”)

For the following code:

grade = 86

if (grade >= 90):
  print("A")
elif (grade >= 80):
  print("B")
elif (grade >= 70):
  print("C")
elif (grade >= 60):
  print("D")
else:
  print("F")

grade is 86
so (grade >= 90) is False
so A is not printed

next (grade >= 80) is True
so B is printed

but none of the other conditions afterward are checked
because
if one of the elif conditions is True, then that block is executed;
but all the elif and else stuff afterward [after the true one] do not get executed.

2 Likes

Thank you very much.