python - While loop user input in range -


i have code want ask user number between 1-100 , if put number between these print (size: (input)) , break loop, if however, put in number outside 1-100 print (size: (input)), , proceed re-ask them number, have run problems though.

c=100 while c<100:     c=input("size: ")     if c == 1 or 2 or 3:         print ("size: "+c)         break     else:         print ("size: "+c)         print ("invalid input. try again.") 

this should it.

c=input("size: ") while int(c)>100 or int(c)<1:      #will repeat until number between 1 , 100, inclusively.     #it skip loop if value between 1 , 100.      print ("size: "+c)     print ("invalid input. try again.")     c=input("size: ")  #once loop completed, code following loop run print ("size: "+c) 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -