Python Forum
4 tries choice question, one difficulty
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
4 tries choice question, one difficulty
#4
pyzyx... shows how you need to use a list to fix one set of bugs.

Another is the logic of your loop. Write it out in English, then code each step.
1. Get the guess (you do this, though you may want to convert to lower case so you don't tell a guess of RED that it is wrong
2. If the guess is correct, inform the user and exit - you do this correctly also, though read on.
3. If the guess in incorrect, increment your counter. If the counter is 4 then print a losing message and exit. If the counter is less than 4 then print a message and loop back. This you do incorrectly. Do the steps in order.

Now, a minor peeve. I personally don't like while True: The reason is that you are setting up an infinite loop and trusting that you are catching every eventuality that requires a break. Minor difference, but I find the following to be easier to maintain
go = True 
while go:
    choice = input("Enter rainbow colour: ")
    if choice in rainbow:
        print("Correct")
        go = False
    else:
        tries += 1
        if tries == 4:
            print("Out of tries")
            go = False
        else:
            print("Try again")
Small differences from your code - define go, use go in the while statement, then change your breaks to making go False. And fixed the final logic. You were very close, still need to fix the code to make rainbow a list.
Reply


Messages In This Thread
RE: 4 tries choice question, one difficulty - by jefsummers - Jun-03-2020, 06:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Difficulty when trying to call all the input values extricate 2 2,045 Jun-05-2020, 09:36 AM
Last Post: pyzyx3qwerty
  Writing python function difficulty kirito85 5 3,447 Oct-28-2018, 07:34 AM
Last Post: buran
  Increasing difficulty of a maths game Maxxy_Gray 1 3,308 Apr-04-2018, 03:00 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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