-2

Tell me the code that would support this, because if I enter a word into an integer input the program crashes. I know this would be a simple one line code, but I just can't get my head around it.

Traceback (most recent call last):
  File "N:/Controlled Assessment/Task Three v1.py", line 9, in <module>
    c1_strength = int(input("What is character 1's strength? (Between 1 and 50, must be number): ")) #asks user for the strength value of character 1
ValueError: invalid literal for int() with base 10: 'fresd'
Bach
  • 5,939
  • 7
  • 30
  • 59

1 Answers1

2

Try this:

while True:
    try:
        a = int(input())
    except ValueError:
        print "Enter an integer"
        continue
    break
Aswin Murugesh
  • 10,230
  • 10
  • 37
  • 68