+ 2

I want to add input code to a try-exception code, How do this ?

I want to add something like this my_input = int(input("please enter input: ")) to this: https://code.sololearn.com/cotMyjwiWN09/#py How may I do this ?

27th Jan 2018, 10:22 AM
NIMA
NIMA - avatar
3 odpowiedzi
+ 11
try: num = int(input()) print ("I was DONE !") except: print("An error occurred") raise
27th Jan 2018, 10:25 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
specify which type of error/errors try: x = int(input("enter an integer: ")) y = 6 / x print(y) except (ZeroDivisionError, ValueError) as e: print(e) print("something happened.....")
27th Jan 2018, 10:36 AM
Burey
Burey - avatar
+ 2
Thanks Hatsy I think this modified code is more accurate: https://code.sololearn.com/cjXempf2Xa8D/?ref=app
27th Jan 2018, 10:37 AM
NIMA
NIMA - avatar