Python Forum
Simple beginner query--Please help!Thanks - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Simple beginner query--Please help!Thanks (/thread-27897.html)



Simple beginner query--Please help!Thanks - Nienie - Jun-26-2020

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
....



RE: Simple beginner query--Please help!Thanks - DPaul - Jun-26-2020

Hi, it is not because 9 is also a number that it is always a number.
expecially not with the imput() statement.
Paul


RE: Simple beginner query--Please help!Thanks - perfringo - Jun-26-2020

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”


RE: Simple beginner query--Please help!Thanks - pyzyx3qwerty - Jun-26-2020

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: "))