Detect if input is a alphabet in python 3.5? -
hello part of code i'm working on. wanted know if there way detect if input typed alphabet , give response. need subtracted time converted int if other int type if gives me error.
def continue(): time = int(input("what time it?: ")) if time > 12: print ("i'm sorry, hour, don't need anymore that.") continue() else: print ("it's %d" % time + "?!") time = time - 1 print ("i'm late!\ni'm sorry have go!\ni'm sure leg fine walk off!") print ("i suppose there @ %d" % time, "i'm hour late!")
this want:
def continue(): try: time = int(input("what time it?: ")) except valueerror: print('invalid input.') print('please enter number between 1 , 12.') continue() if time > 12: print("i'm sorry, hour, don't need anymore that.") continue() else: print("it's %d" % time + "?!") time = time - 1 print ("i'm late!\ni'm sorry have go!\ni'm sure leg fine walk off!") print ("i suppose there @ %d" % time, "i'm hour late!")
you can use try
-except
statement. python raise valueerror
if conversion integer fails. in case, catch exception except
, tell user input wrong, , call function again.
Comments
Post a Comment