Hi, can someone please help me out here. Its Intro to Programming: Conditions and Conditional Statements: Question 1.
I tried to solve the problem other than usual, starting with the lowest score.
I thought the function would run through all elifs. Now I assume if an elif statement is true it skips the other elifs, otherwise it should set the score to C in the 2nd elif statement.
Is that assumption correct?
Incorrect: Expected return value of 'C' given score=70, but got 'D' instead.
# TODO: Edit the function to return the correct grade for different scores
def get_grade(score):
if score < 60:
grade = "F"
elif score >= 60:
grade = "D"
elif score >= 70:
grade = "C"
elif score >= 80:
grade = "B"
elif score >= 90:
grade = "A"
return grade
# Check your answer
q1.check()
Correct
# TODO: Edit the function to return the correct grade for different scores
Solution:
def get_grade(score):
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
elif score >= 60:
grade = "D"
else:
grade = "F"
return grade