Mar-14-2023, 04:56 PM
(This post was last modified: Mar-14-2023, 05:00 PM by deanhystad.)
If you don't want to show the answer, why do you print it?
Your other error is a bit more subtle. After you generate a random number you want to give the player multiple tries to guess the correct number. That means you need a loop after you generate the random answer. Your code also does some input verification that uses a loop. That would be inside the guessing loop. The overall layout is like this:
You could write this as a bunch of nested loops, but it would be better organized as a group of functions
Your other error is a bit more subtle. After you generate a random number you want to give the player multiple tries to guess the correct number. That means you need a loop after you generate the random answer. Your code also does some input verification that uses a loop. That would be inside the guessing loop. The overall layout is like this:
display welcome banner WHILE PLAYING GENERATE RANDOM NUMBER WHILE GUESSING WHILE VERIFYING VERIFY INPUT CHECK IF INPUT IS CORRECT ASK IF PLAY AGAIN display thanks for playing bannerYou have most of these code pieces except the guessing loop, and some of your pieces aren't in the right place. For example, your ask if play again code needs to be inside the WHILE playing loop.
You could write this as a bunch of nested loops, but it would be better organized as a group of functions
def get_guess(): """ Get user's guess """ ... def play_game(): """ Play the guessing game """ ... def play_again(): """ Returns True if user wants to play again """ ... print(welcome_banner) while True: play_game() if not play_again(): break print(thanks_for_playing_banner)