Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Need very simple coding help (python)

1. ## Need very simple coding help (python)

Very very simple help for noob beginner in python. Trying to make a very simple game of "Guess the magic number." I've set the variable MagicNumber = 3. Then I set the input to the first question to the variable x. I think something went wrong in my if, is, else statement areas. I'm am sorry if this is considered spam or something but i'm trying to learn so help would be much appreciated! I'll attach a photo and a notepad document as well as write the code out here:
--------------------------------------------------------------------------------------------------------------------------------------
#Guess the magic number

MagicNumber = 3
x = (input("Guess the magic number "))
if x is MagicNumber: # I'm thinking there is something wrong in this line of code.
print(MagicNumber, " is the magic number!")
else:
print("Sorry wrong number. Try again!")

'''
Program starts by asking magic number
then when user inputs number it will give out the else statement "Sorry wrong number. Try again!"
even if they guess the right number
'''
--------------------------------------------------------------------------------------------------------------------------------------

Guessthemagicnumber.txt

• I don't speak Python, but surely it should be
if x == MagicNumber:

• Originally Posted by Philip M
I don't speak Python, but surely it should be
if x == MagicNumber:
Still prints the else statement even when input is 3 when change is to ==

• Originally Posted by Diordna
Still prints the else statement even when input is 3 when change is to ==
Just played around with it. I had to bind magic number to the string 3 ('3') in order for it to compare the user input with the magic number. Thanks though! =)

• Better than comparing to "3" would be to compare NUMBER TO NUMBER.

So just do
Code:
`x = int(input("Guess the magic number "))`

• Ah - it seems that Python (unlike Javascript) does not do type conversion.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•