Question

Enum Write an enum type called TrafficSignal, which contains the constants RED, GREEN, YELLOW, WALK, DONT_WALK...

Enum

Write an enum type called TrafficSignal, which contains the constants RED, GREEN, YELLOW, WALK, DONT_WALK with each constant having a parameter for the duration of the constant (have the duration be in terms of seconds). Write a program that tests the TrafficSignal enum so that it displays each enum constant and the duration of the enum constant.

please include Your Programmer Documentation text file (or your documentation as a block comment in the main program)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import enum
# Using enum class to create enumerations
class TrafficSignal(enum.Enum):
RED = 30 #providing 30secs of Red Light
YELLOW = 3 #providing 3secs of Yellow Light
GREEN = 45 #providing 45secs of Green Light
WALK = 20 #providing 20secs to Walk
DONT_WALK = 50 #providing 50secs not to Walk

for status in TrafficSignal: #looping through all the enums
print (status.name ,":", status.value,"secs")#displaying enums on terminal

Add a comment
Know the answer?
Add Answer to:
Enum Write an enum type called TrafficSignal, which contains the constants RED, GREEN, YELLOW, WALK, DONT_WALK...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT