Computer Science, asked by SHASMECKA123, 1 month ago

(b) Write a program in Python that accepts the colour of traffic signal from the user and displays the
appropriate message according to the table given below.
(Use if…elif to write the program)

Traffic Signal Display Message
RED STOP
GREEN GO
YELLOW READY
Any other entry INVALID ENTRY

Answers

Answered by Anonymous
4

Hm I'm not quite sure what you actually want to achieve. Your version does not loop since the break statement will always be met after the first iteration. Additionally, you only ask for user input once before the loop actually starts.

Here is what I suppose you want to do, so I moved the user input part inside the loop and added the break condition to the pythonic "switch" statement. This will just ask the user for input for as long as he doesn't enter 30.

while True: x = input("Enter value: ") stop_light = int(x) if stop_light == 30: break elif stop_light >= 1 and stop_light < 10: print('Green light') stop_light += 1 elif stop_light < 20: print('Yellow light') stop_light += 1 elif stop_light < 30: print("Red light") stop_light += 1 else: stop_light = 0

Answered by kanishkagupta1234
1

 \huge \colorbox{pink}{Answer}

A Pythagorean triple consists of three positive integers a, b, and c, such that a2 + b2 = c2. ... The name is derived from the Pythagorean theorem, stating that every right triangle has side lengths satisfying the formula a2 + b2 = c2; thus, Pythagorean triples describe the three integer side lengths of a right triangle.

Similar questions