Hi,
Been working my way through the LP3THW book…been fun so far and learning a lot.
Thought I was understanding ex31…if - elif - else statements. However, when I tried to create my own game using them, I realized that I’m not understanding how to get the flow right when getting user input.
When running script and entering the correct answer, I get another prompt after the print statement shows up, instead of script just stop running.
If I enter an incorrect choice, it doesn’t run the ‘second_guess’.
Also, need to create a ‘third_guess’ in case the ‘second_guess’ is incorrect.
I’d like to get this version of script to run correctly so that I learn/understand how to use if - elif - else properly.
After that, would like to create another version of this game as it seems this version is more complicated way to do this than necessary. Thinking there’s a simpler logic flow approach in that either user enters the right answer on the first try and then game should end or any wrong answer (ie, not 3…), should trigger the ‘second_guess’ to run and not a separate if -elif - else statement for each separate number entry.
Appreciate any help with this!
Mark
Here’s my current version of the game:
print("Guess my favorite musician or group")
print("You get 3 guesses to win a prize") print("Enter 1 for Elvis, 2 for Beatles, 3 for Stones, 4 for Led Zep, 5 for The Who.")
first_guess = input("> ")
if first_guess == "1":
print("Sorry, not correct.")
print("Try again.")
elif first_guess == "2":
print("Sorry, try again.")
elif first_guess == "3":
print("That's it! You get a prize!")
print("Good job!")
elif first_guess == "4":
print("Sorry, try again.")
elif first_guess == "5":
print("Sorry, try again")
second_guess = input("> ")
if second_guess == "2":
print("Nice try, but incorrect. Try one more time.")
elif second_guess == "3":
print("Great! That's it! A prize for you!")
elif second_guess == "4":
print("Sorry, no prize for you")
elif second_guess == "5":
print("Nope, that's not right.")