'>' not supported between instances of 'str' and 'int' in my guess the number game

前端 未结 1 1737
有刺的猬
有刺的猬 2020-12-11 14:02

In my guess the number program it gives me the error: \'>\' not supported between instances of \'str\' and \'int\' on line 26 in main. I would be grateful if someon

相关标签:
1条回答
  • 2020-12-11 14:38

    By default, input returns a string. You need to convert your input to a numeric type, in this case integer.

    Replace:

    guess = input("Guess a number: ")
    

    With:

    guess = int(input("Guess a number: "))
    

    You may also wish to validate user input to ensure that you have actually been provided with a valid integer. For this you should see Asking the user for input until they give a valid response.

    0 讨论(0)
提交回复
热议问题