Help with guessing game :D
Robert Gonda
robertgonda1994 at gmail.com
Tue Oct 29 07:45:39 EDT 2013
Hey guys, so I figured I will give python a shot. I got to exercise that has asked me to create a number guessing game which weren't a problem,
guessesTaken = 0 #This is a "Guesses taken counter"
print("Hello, what's your name?") #Asking the user to input their name
N = raw_input() #What the user's name is
import random #This is importing the random function
number = random.randint(1, 999) #This tells the random function to generate a random number between 1 to 1000
print(N + ", I'm thinking of a number between 1-1000") #Not needed but tells the user their name and tells them that it's thinking of a number betweeen 1 to 1000
while guessesTaken < 10:
print('Take a guess.')
guess = input()
guess = int(guess)
guessesTaken = guessesTaken + 1
if guess < number: #Says that if the guess is too low it will print a message saying that the guess is too low
print('Your guess is too low.')
if guess > number: #Says that if the guess is too high it will print a message saying that the guess is too high
print('Your guess is too high.')
if guess == number:
break #Breaks the loop, meaning it will continue to loop for 10 times while giving them messages from above depending on their results
if guess == number:
guessesTaken = str(guessesTaken)
print("Congrat's, " + N + "! You managed to get the number in " + guessesTaken + " guesses!") #Tells the user they managed to guess it in x number of times
if guess != number: #If the user is unable to guess the number in 10 times it will stop the loop and give the user a message
number = str(number)
print("No, the right number was" + number)
However the problem is that it also asked me to do the following : If at least one of the digit guessed is right it will say "y" otherwise "n" which I can't seem to do :/ any help?
More information about the Python-list
mailing list