Hi everyone,
Just learning python for the first time but I am having some difficulties.
I'm having some trouble with the code below:
Also, I noticed that if I change the bottom bit to the code below (then I always get the output that I lost the game even when I won):
Thanks,
voltman
Just learning python for the first time but I am having some difficulties.
I'm having some trouble with the code below:
minGuess = 1
maxGuess = 6
#Ask the user for their name and their maxGuess
name = input("What is your name? ")
print("Hi " + name + "!")
print("Enter a number between: " + str(minGuess) + " and " + str(maxGuess))
guess = int(input("What is your guess? "))
#Generate a random number and tell the user if they won or lost
import random
secretNumber = random.randint(minGuess, maxGuess)
if (guess == "secretNumber"):
print("Congratulations, you got it right!")
else:
print("You lose - the number was " + str(secretNumber))
print("Thank you for playing Guess the Number.")It won't output "Congratulations, you got it right" even if I correctly guess.Also, I noticed that if I change the bottom bit to the code below (then I always get the output that I lost the game even when I won):
if (guess != "secretNumber"):
print("You lose - the number was " + str(secretNumber))
else:
print("Congratulations, you got it right!")
print("Thank you for playing Guess the Number.") What did I do wrong? Any help would be much appreciated.
Thanks,
voltman
