Dec-13-2018, 05:45 PM
Dec-13-2018, 06:27 PM
Try this
answer = input("Enter something: ") try: value = int(answer) print("it is an integer") except ValueError: print("it is not an integer")
Dec-13-2018, 06:59 PM
(Dec-13-2018, 06:27 PM)Gribouillis Wrote: [ -> ]Try this
answer = input("Enter something: ") try: value = int(answer) print("it is an integer") except ValueError: print("it is not an integer")
thank you a lot dude

Dec-13-2018, 11:39 PM
I also use mostly try/except way proposed by @Gribouillis.
But look at the string methods isdecimal, isdigit, isnumeric.
But look at the string methods isdecimal, isdigit, isnumeric.
answer = input("Enter something: ") if answer.isnumeric(): number = int(answer) else: # do something else.