Python Forum

Full Version: Simple beginner query--Please help!Thanks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I am a very fresh learner and have a question regarding the guess number game below. Please help!

My question is the result still goes 'Let's try again' even when I try 9, which is the correct one.

The code I type:
>>> while True:
      value=input("Please guess a number:")
      if value==int('9'):
        print("Good!")
      else:
        print("Let's try again!")
        continue
        break
....
Hi, it is not because 9 is also a number that it is always a number.
expecially not with the imput() statement.
Paul
You should convert user input (value) to int and then compare it to 9 (if int(value) == 9)

However, there is no need for conversion. One can just if value == “9”
No need to do
if value==int('9'):
Python doesn't understand what do you mean by that, and hence, doesn't produce the expected output
You can do
if value == 9 :
If you want the input to directly become an integer, you can do
value = int(input("Enter a number: "))