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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -