python - Python3: creating error for input of negative -
taking intro course , need create over/under guessing game. want fine-tune user inputs creating error if inputs negative or non-integer. have non-integer error reporting correctly, , negative loops correctly, negative not print error message.
#number of plays def get_plays(msg): while true: try: x = (int(input(msg))) except valueerror: print ("integer numbers please.") except: if x <=0: print ("positive numbers please.") = get_plays("\nhow many times play?") print ("the game play " +str(i)+" times.")
separately, if wanted use similar setup produce error negative non-integer number between 1 , 20, how look?
try:
def get_plays(msg): while true: try: x = (int(input(msg))) if x <=0: print("positive numbers please.") continue if x not in range(20): print("enter number between 1 - 20.") continue return x except valueerror: print("integer numbers please.")
it accept positive numbers between 1 20
Comments
Post a Comment