Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Simple beginner query--Please help!Thanks
#1
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
....
Quote
#2
Hi, it is not because 9 is also a number that it is always a number.
expecially not with the imput() statement.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu)
Quote
#3
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”
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Quote
#4
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: "))
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Query in list.clear (beginner) Shaswat 1 409 Apr-30-2019, 01:54 PM
Last Post: ichabod801

Forum Jump:


Users browsing this thread: 1 Guest(s)