-1

When i enter a non number in this code it breaks with this message:

Traceback (most recent call last): File "C:/Users/Default/Desktop/AS91076.py", line 12, in temp = int(input("At what Temperature do you want your wash? (Maximum 40 Degrees)")) ValueError: invalid literal for int() with base 10: 'asdf'

        temp = int(input("At what Temperature do you want your wash? (Maximum 40 Degrees)"))
        if temp < 41:
        **Misc Code**
        else:
            print("Not a valid Temperature!")
Paul R
  • 208,748
  • 37
  • 389
  • 560
Bob
  • 11
  • 2

1 Answers1

1

An arbitrary string can not be converted to a number. If you want to catch cases when the user types a non-integer, you can use the try statement.

try:
    temp = int(input("At what Temperature do you want your wash? (Maximum 40 Degrees)"))
    if temp < 41:
        **Misc Code**
    else:
        print("Temperature too high!")
 except ValueError as e:
        print("Not a valid Temperature!")
sauerburger
  • 4,569
  • 4
  • 31
  • 42