error handling | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

error handling

I defined this function in python. When a person presses the submit button without imputing a value, I want to only display the first two print messages. how can I handle the error part to silence it from being output? def level(): print ("PRESS RUN AND ENTER A VALUE BETWEEN 0 AND 10 ON THE INPUT BOX") print ("=============================================================") score=int(input("your level of expertise:")) if score <5: return 'novece' elif score <=7: return 'intermediate' elif score <=10: return 'expert' else: return "Invalid input, use a value between 0 and 10" print (level())

11th Jun 2019, 9:16 AM
NJUGUNA MUIRURI
NJUGUNA MUIRURI - avatar
2 Answers
+ 2
def level(): print("PRESS RUN AND ENTER A VALUE BETWEEN 0 AND 10 ON THE INPUT BOX") print("=============================================================") try: score = int(input("your level of expertise:")) if score < 5: return "Novece" elif score <= 7: return "Intermediate" elif score <= 10: return "Expert" else: return "Invalid input, use a value between 0 and 10" except: return "" print(level())
11th Jun 2019, 12:30 PM
Diego
Diego - avatar
+ 5
not return use print!
11th Jun 2019, 9:27 AM
CodeFu
CodeFu - avatar