Python Forum
Conditionals, while loops, continue, break (PyBite 102)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Conditionals, while loops, continue, break (PyBite 102)
#3
Ding, ding, ding! I pulled it off, thanks to @bowlofred's advice.

I replaced the second and third instances of the break operator with continue. I also removed the second and third instances of print("bye"). When I ran the test script, it passes all 5 checks. Cool

For what it is worth, here is my final script in full:

VALID_COLORS = ['blue', 'yellow', 'red']


def print_colors():
    """
    In the while loop ask the user to enter a color, lowercase it and store it in a variable. Next check: 
       - if 'quit' was entered for color, print 'bye' and break. 
       - if the color is not in VALID_COLORS, print 'Not a valid color' and continue.
       - otherwise print the color in lower case.
    """
    while True:
        chosen_color = input("What color do you choose?")
        low_chosen_color = chosen_color.lower()
        if low_chosen_color == "quit":
            print("bye")
            break
        elif low_chosen_color not in VALID_COLORS:
            print("Not a valid color")
            continue
        elif low_chosen_color in VALID_COLORS:
            print(f"{low_chosen_color}")
            continue
        pass
Thanks @bowlofred for your help. Big Grin

I meant to reply sooner. Sorry for the delay.
Reply


Messages In This Thread
RE: Conditionals, while loops, continue, break (PyBite 102) - by Drone4four - Jun-04-2020, 12:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  for loops break when I call the list I'm looping through Radical 4 893 Sep-18-2023, 07:52 AM
Last Post: buran
Question Doubt about conditionals in Python. Carmazum 6 1,604 Apr-01-2023, 12:01 AM
Last Post: Carmazum
  conditionals based on data frame mbrown009 1 900 Aug-12-2022, 08:18 AM
Last Post: Larz60+
  Efficiency with regard to nested conditionals or and statements Mark17 13 3,170 May-06-2022, 05:16 PM
Last Post: Mark17
  Nested conditionals vs conditionals connected by operators dboxall123 8 3,064 Feb-18-2022, 09:34 PM
Last Post: dboxall123
  Break out of nested loops muzikman 11 3,352 Sep-18-2021, 12:59 PM
Last Post: muzikman
  Nested Conditionals shen123 3 2,634 Jul-28-2021, 08:24 AM
Last Post: Yoriz
  How to break out of nested loops pace 11 5,376 Mar-03-2021, 06:25 PM
Last Post: pace
  Invalid syntax using conditionals if - else jperezqu 1 2,336 Jan-13-2021, 07:32 PM
Last Post: bowlofred
  Sorting list of names using a lambda (PyBite #5) Drone4four 2 2,737 Oct-16-2020, 07:30 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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