Join the IDNLearn.com community and start exploring a world of knowledge today. Our platform offers reliable and comprehensive answers to help you make informed decisions quickly and easily.

2.9.8 stop light codehs
I cant figure out how to do this stop light function on codehs help
(this is the assignment)
Write a program that prompts the user for a color: red, yellow, or green (the colors of a stoplight). Then using if statements and else statements, print the user a message describing what they should do. For example if the color was red, you could say something like, “Red light: you should stop.”

As a bonus, see if you can use “else if” in this problem. Check out “else if” in the “Docs” tab.

You may assume the user will only input “red”, “yellow”, or “green”. You do not have to worry about other colors, or mixed capitalization such as “blue” or “ReD”, but you can make your program handle these cases if you wish!


Sagot :

The program illustrates the use of conditional statements

Conditional statements are statements used to make comparison and decisions

How to write the program?

The program written in Python, where comments are used to explain each action is as follows:

#This gets input for the color

color = input("Color: ").lower()

#This checks if the input is red

if color == "red":

   print(“Red light: you should stop.”)

#This checks if the input is yellow

elif color == "yellow":

   print(“Yellow light: you should get ready.”)

#This checks if the input is green

elif color == "green":

   print(“Green light: you should go.”)

#This checks for invalid input

else:

   print(“Invalid")

Read more about Python programs at:

https://brainly.com/question/24833629