-2

I don't know how to receive user input or how to print out the results for this problem.

def determine_grade(x):
    while x > -1 and x < 101:
        if x >= 90:
            return 'You got an A'
        elif x >= 80:
            return 'You got a B'
        elif x >= 70:
            return 'You got a C'
        elif x >= 65:
            return 'You got a D'
        elif x <= 65:
            return 'You got an F'
        else:
            return 'Terrible'

x = input("Type in your grade: ")

It just asks me to enter a grade, and then says finished with exit code 0.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135

3 Answers3

0
def determine_grade(x):
    while x > -1 and x < 101:
        if x >= 90:
            return 'You got an A'
        elif x >= 80:
            return 'You got a B'
        elif x >= 70:
            return 'You got a C'
        elif x >= 65:
            return 'You got a D'
        elif x <= 65:
            return 'You got an F'
        else:
            return 'Terrible'
x = input("Type in your grade: ")
print(determine_grade(int(x)));

the input value's type default is string before you pass it to determine_grade, you must convert it to int.

Guokas
  • 750
  • 7
  • 23
0

x = input("Type in your grade: ") => Store your input as a string

def determine_grade(x): => use this function by calling it determine_grade(int(x)) - convert str to int before use x as an input

Ex:

>>> x = input("Type in your grade: ")
Type in your grade: 2
>>> x
'2'
>>> determine_grade(int(x))
'You got an F'
Lê Tư Thành
  • 1,063
  • 2
  • 10
  • 19
0

After this line x = input("Type in your grade: ") call the function with the variable x as the parameter. you have to first convert the datatype of the x variable to int as the input function returns the user input in string format. Use the int function to convert to string.

x = input("Type in your grade: ")
determine_grade(int(x))

alternatively you can use print to display the output

print(determine_grade(int(x)))
Sashaank
  • 880
  • 2
  • 20
  • 54