Jun-03-2020, 06:28 PM
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
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.