Guess my ID game: Use python while loops to make your friends guess your ID.
Store your ID in a variable called myID.
After students run your code, they will guess what your ID. Is.
Those who don't guess the number will be stuck in an endless loop!
Those who guess the number will end the loop and get a congratulations message!
Start your code with the following message:
Hi, my name is your name. Welcome to my game.
Guess my number
If the number chosen by the user is different than your ID, the user should see the message “You're stuck in my loop!" and be prompted to enter a number again.
If the number entered by the user matches your ID, the number should be printed to the screen, and you should say the following words: "Well done! You are free now."
myName = "Mr.x"
myID = "999"
startMsg = "Hi, my name is {}. Welcome to my game.".format(myName)
guessMsg = "Guess my number"
stackMsg = "You're stuck in my loop!"
winMsg = "Well done! You are free now."
print(startMsg)
while True:
print(guessMsg)
s = input()
if s == myID:
print(myID, winMsg, sep='\n')
break
print(stackMsg)
Comments
Leave a comment