Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Higher or lower game
#7
(Mar-14-2023, 04:56 PM)deanhystad Wrote: 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:
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 banner
You 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)
    
Where would I add the guessing loop and what type of loop should I use
Reply


Messages In This Thread
Higher or lower game - by SEWII - Mar-13-2023, 05:42 AM
RE: Higher or lower game - by jefsummers - Mar-13-2023, 06:43 PM
RE: Higher or lower game - by SEWII - Mar-14-2023, 03:24 AM
RE: Higher or lower game - by SEWII - Mar-14-2023, 03:25 AM
RE: Higher or lower game - by deanhystad - Mar-14-2023, 04:56 PM
RE: Higher or lower game - by SEWII - Mar-14-2023, 06:33 PM
RE: Higher or lower game - by jefsummers - Mar-14-2023, 04:57 PM
RE: Higher or lower game - by SEWII - Mar-14-2023, 06:34 PM
RE: Higher or lower game - by deanhystad - Mar-14-2023, 07:38 PM
RE: Higher or lower game - by SEWII - Mar-15-2023, 12:30 AM
RE: Higher or lower game - by jefsummers - Mar-15-2023, 01:22 PM
RE: Higher or lower game - by SEWII - Mar-15-2023, 06:31 PM
RE: Higher or lower game - by SEWII - Mar-15-2023, 06:33 PM
RE: Higher or lower game - by jefsummers - Mar-15-2023, 06:56 PM
RE: Higher or lower game - by SEWII - Mar-15-2023, 07:11 PM
RE: Higher or lower game - by deanhystad - Mar-15-2023, 07:00 PM
RE: Higher or lower game - by SEWII - Mar-15-2023, 07:10 PM
RE: Higher or lower game - by jefsummers - May-28-2023, 11:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract lower/upper antitriangular matrix schniefen 2 1,456 Dec-09-2022, 08:57 PM
Last Post: Gribouillis
  Check if all the numbers are higher than five and if not... banidjamali 3 2,154 Jan-11-2021, 11:25 AM
Last Post: banidjamali
  HELP - Returning self numbers lower or equal to my argument Kokuzuma 4 2,768 Nov-01-2018, 06:35 PM
Last Post: Kokuzuma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020