+ 1

I wrote a simple code by using function definition that computes grades. Why do I get Traceback error for non integers inputs?

https://code.sololearn.com/cDi9T1dIyKp6/?ref=app

13th May 2018, 1:22 PM
IKECHUKWU, GAVIN C
IKECHUKWU, GAVIN C - avatar
5 odpowiedzi
+ 21
Whithawk u have declared user_input in while loop so it is not accessible outside while loop.... try this 👇 https://code.sololearn.com/c6bagyJ0u9wt/?ref=app
13th May 2018, 1:46 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 1
you try to convert your input to an int... so 45.5 raises an error...
13th May 2018, 1:25 PM
Amaras A
Amaras A - avatar
+ 1
Thanks alot 🌛DT🌜. I stil have a lot to learn. I just started learning python though.
13th May 2018, 1:50 PM
IKECHUKWU, GAVIN C
IKECHUKWU, GAVIN C - avatar
0
Amaras A thank you. However it stil gives a Traceback error for input that are not numbers.. Like letters.
13th May 2018, 1:31 PM
IKECHUKWU, GAVIN C
IKECHUKWU, GAVIN C - avatar
0
I think I fixed it. def computegrades(x): if x >= 70: print("A") elif x >=60: print("B") elif x >=50: print("C") elif x >=45: print("D") elif x <45: print("F") else: print("invalid score. Try again") return user_input = input("Type your score to compute grade: ") if user_input.isdigit(): x = int(user_input) computegrades(x) else: print("That is not a valid number. Try again!")
13th May 2018, 1:46 PM
IKECHUKWU, GAVIN C
IKECHUKWU, GAVIN C - avatar