Python prints function grade_value

values for letter grades

A = 95
B = 85
C = 75
D = 65
E = 55
F = 0

get user grade

grade = input('Enter your grade: ')
grade = str(grade)

function to return grade value as int

def grade_value(user_grade):
    if user_grade == 'A':
        return A
    elif user_grade == 'B':
        return B
    elif user_grade == 'C':
        return C
    elif user_grade == 'D':
        return D
    elif user_grade == 'E':
        return E
    elif user_grade == 'F':
        return F
        return('Error: Invalid grade')

call function and print value

value = grade_value(grade)
if isinstance(value, int):
    print(f"The value of {grade} is {value}")

I would like for it to return the value of the grade.

>Solution :

currently, your function grade_value is returning the value you want to print. However, when you call the function and try to print the result, you’re actually printing the memory location of the function itself. That’s not what you want to do!

To fix this. First, assign the result of grade_value(grade) to a variable, and then print the variable. This way, you’ll be printing the actual value you want to see.

result = grade_value(grade)

Leave a Reply