0

I'm creating a quiz game where if a user types a number beyond a set amount or a word instead, it forces it to print an error message and go back to the start. I understand how to use the > than for the number, but have tried to use string, string == False, not alpha etc and keep getting the same error messages regarding int and string.

    while True:
        quiz=int(input("What answer do you think is right? Choose 1- 20"))
        if quiz >20:
            print("Oops, That's too high")
        else:
            print("Not a number")
            continue:
            break

1 Answers1

0

You're not checking that the string can actually be converted to an int, before typecasting your input to int.

You can use isdigit for this.

And you should be calling .isalpha() instead of isalpha

Pythonista
  • 11,377
  • 2
  • 31
  • 50