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
#1
Hi there,

I have come up with this code, after 4 tries, it is supposed to say "Out of tries" but before it says "Out of tries", it will say "Try again"

Any idea what correction is needed to prevent "Try again" from appearing after the fourth try and have the code say "Out of tries" straight away?

rainbow = "red, orange, yellow, green, blue, indigo, violet"
tries = 0

rainbow = "red, orange, yellow, green, blue, indigo, violet"
tries = 0

while True:
    choice = input("Enter rainbow colour: ")
    if choice in rainbow:
        print("Correct")
        break
    else:
        tries += 1
        print("Try again")
        if tries == 4:
            print("Out of tries")
            break
        else:
            pass
Reply


Messages In This Thread
4 tries choice question, one difficulty - by extricate - Jun-03-2020, 07:04 AM

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