Hi everyone,
Just learning python for the first time but I am having some difficulties.
I'm having some trouble with the code below:
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):
What did I do wrong? Any help would be much appreciated.
Thanks,
voltman
Just learning python for the first time but I am having some difficulties.
I'm having some trouble with the code below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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." ) |
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):
1 2 3 4 5 |
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." ) |

Thanks,
voltman