Python Forum
Program: Input the correct color
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program: Input the correct color
#1
# [ ] use a while True loop (forever loop) to give 4 chances for input of a correct color in a rainbow
# rainbow = "red orange yellow green blue indigo violet"

while True:
    rainbow = "red orange yellow green blue indigo violet"
    try1 = input("try color: ")
    try2 = input("try color: ")
    try3 = input("try color: ")
    try4 = input("try color: ")
    if try1 in rainbow:
        print("You guessed the colour!")
    elif try2 in rainbow:
        print("You guessed the colour!")
    elif try3 in rainbow:
        print("You guessed the colour!")
    elif try4 in rainbow:
        print("You guessed the colour!")    
    else:
        print("Better luck next time!")
I assume that this is not optimal solution. I at first tried with if try1 or try2 or try3 or try4 in rainbow: but that doesn't work. Advice is appreciated.
Reply


Messages In This Thread
Program: Input the correct color - by Truman - Jan-19-2018, 10:59 PM
RE: Program: Input the correct color - by j.crater - Jan-19-2018, 11:19 PM
RE: Program: Input the correct color - by Mekire - Jan-19-2018, 11:21 PM
RE: Program: Input the correct color - by Truman - Jan-19-2018, 11:35 PM
RE: Program: Input the correct color - by Mekire - Jan-19-2018, 11:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation How to get program to loop if input date is in the past? xander_thornton45 3 1,898 Oct-11-2024, 10:08 AM
Last Post: Pedroski55
  User input numpy array with color mapping & mouse click events imakeathepi 0 3,845 Aug-15-2017, 10:33 AM
Last Post: imakeathepi

Forum Jump:

User Panel Messages

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