Answer to Question #193891 in Python for ali

Question #193891

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." 



1
Expert's answer
2021-05-15T14:44:11-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS