+ 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())
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())
+ 5
not return use print!