1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2013
Posts
2
Rep Power
0

#### Help!

I'm a newbie to Python, and I was trying to make a number guessing game, using Python 3.

Even if you choose the right number, it says you've lost- why, and how do I fix it? Keep in mind I'm new to programming, so just tell me why, without using too much hi-tech vocabulary which I don't understand!

Here is my script:

enter = "Please press Enter to continue..."

import random

myName = input ("Hello, what is your name? ")

print ("Ok, "+myName+", guess a number between 1 and 5")

number = random.randint(1, 1)

Guess1 = input(""+myName+"'s first guess is... ")
if Guess1 == number:
print ("Well done- "+myName+", you win! Your prize is safe in the arms of this penguin!")
input (enter)
sys.exit(0)
else:
print ("Sorry, try again!")
print ("Two more guesses...")
Guess2 = input (""+myName+"'s second guess is... ")
if Guess2 == number:
print ("Well done- "+myName+", you win! Your prize is safe in the arms of this penguin")
input (enter)
sys.exit(0)
else:
print ("Sorry, try again!")
print ("Last guess- choose wisely!")
Guess3 = input (""+myName+"'s final guess is... ")
if Guess3 == number:
print ("Well done- "+myName+", you win! Your prize is safe in the arms of this penguin")
else:
print ("Sorry, you lose- maybe next time...")
number = str(number)
print ("The number I chose was "+number+"")
input (enter)
sys.exit(0)

brindapari1
2. input return a text value, whereas random return a numeric/integer value.

When you compare two values, you have to make sure both variables are the same type.
This mean you will have to convert the input text to integer:
Code:
`Guess1 = int(input(""+myName+"'s first guess is... "))`