python - How to specify in a code that it must be a number, because if I enter a word in an integer input the program crashes -


this question has answer here:

tell me code support this, because if enter word integer input program crashes. know simple 1 line code, can't head around it.

traceback (most recent call last):   file "n:/controlled assessment/task 3 v1.py", line 9, in <module>     c1_strength = int(input("what character 1's strength? (between 1 , 50, must number): ")) #asks user strength value of character 1 valueerror: invalid literal int() base 10: 'fresd' 

try this:

while true:     try:         = int(input())     except valueerror:         print "enter integer"         continue     break 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -