Reputation: 41
Write a function called evaluate_letter_grade which accepts a single float argument (representing the student's grade) and returns a string which represents the corresponding letter grade. Letter grades are assigned as follows:
Grade Letter
90-100 A
80-89.99 B
70-79.99 C
60-69.99 D
0-59.99 F
Greater than 100 or less than 0 Z
I think I have created my function correctly (maybe), but I can not figure out how to get it to output the correct letter grade. Any suggestions? This is what I have:
def evaluate_letter_grade(grade, lettergrade):
if grade >= 90 or grade <= 100:
lettergrade = "A"
elif grade >= 80 or grade <= 89.99:
lettergrade = "B"
elif grade >= 70 or grade <= 79.99:
lettergrade = "C"
elif grade >= 60 or grade <= 69.99:
lettergrade = "D"
elif grade >= 0 or grade <= 59.99:
lettergrade = "F"
else:
lettergrade = "Z"
return lettergrade
grade = float(input("Enter the student's grade: "))
evaluate = evaluate_letter_grade(grade, lettergrade)
finalgrade = evaluate
print finalgrade
Upvotes: 0
Views: 79
Reputation: 6258
Your function is correct as you have written it, except you only want one input parameter, grade
, the float value of the grade.
Also, why not simply condense:
evaluate = evaluate_letter_grade(grade, lettergrade)
finalgrade = evaluate
print finalgrade
to:
print evaluate_letter_grade(grade)
I think I have created my function correctly (maybe), but I can not figure out how to get it to output the correct letter grade.
Whatever is in your return statement is the "output". In this case you are passing in float values and returning a String. Your function will "resolve" to that return value from which you can assign it to other variables or pass it as a parameter (as you did with the print
function).
Upvotes: 1