Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Execution 4 : Enter the integer: 0 for Red Led, 1 for Yellow, 2 for Green Led: 5 Wrong Led Selection: Try again Enter 0

Execution 4:
Enter the integer:
0 for Red Led, 1 for Yellow, 2 for Green Led: 5
Wrong Led Selection: Try again
Enter 0 to exit or 1 to continue: 1
Enter the integer:
) for Red Led, 1 for Yellow, 2 for Green Led: 3
Wrong Led Selection: Try again
Enter 0 to exit or 1 to continue: 0
End of Execution
Implement code in the provided template Python file to reflect the execution of the
instructor's completed Python script
Coding Architecture Rules:
a. Read the comments provided in the template to implement code
b. You have to implement the code based on the provided comments.
c. You cannot change any code in the provided template file
d. A variable name specified to be used in coding in a comment cannot be changed
e. You cannot change the script flow provided in the template file.
f. Any violations of the architecture rules will result in penalties, and if the violations
are significant, a zero grade will be assigned"""
A Program to turn on an user chosen LED in the Traffic Light,
and allow the user to select different leds repeatdely and
decide when to exit the program
"""
#Import the library RPi.GPIO with alias GPIO
import RPi.GPIO as GPIO
#Import the sleep function from time module
from time import sleep
"""Setting the pin access mode to BCM"""
GPIO.setmode(GPIO.BCM)
"""Define a list collection type named leds and initialize
with the three GPIO pin numbers in broadcom mode to 6,13 and 26
corresponding to red, yellow and green leds connected
Points: 2"""
"""Setup the three GPIO pins to be output pins
using the list variable leds
Points: 2"""
"""A boolean varible initialized to be used as the sentinel in the while loop"""
flag_cont = True
"""A While loop to execute continously until the user
decides to exit"""
while(flag_cont):
"""Write code to prompt the user to select either
red or yellow or green led by entering
0 for Red Led
1 for Yellow Led
2 for Green Led.
Store the user entered integer in a variable named led_idx
Points: 2
"""
print('Enter the integer:')
"""Write conditional statements (if, elif, and else) using led_idx as
the sentinel to branch to a led operation.
1. Only in the if and elif blocks, the corresponding led should be turned
on for the user desired on time, and then turned off.
2. The GPIO pin should be selected using the list collection type variable
leds and the led_idx.
3. The else block should display that the user entered a wrong led
selection.
4. In the if and elif blocks, the user should be prompted to enter the
desired on time, and stored in an appropriate data type
5. In the if and elif blocks, after the led is turned off, display the led
was on for xx secs
Points: 12
"""
"""
Prompt the user to enter 0 for exiting the program
or 1 to continue.
Store the user entered value in the boolean variable flag_cont.
Hint: An integer 0 can be transformed into a boolean type False, and
an integer 1 to boolean type True
Points: 2
"""
print('End of Execution')
GPIO.cleanup()
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain franchising and how this form of business ownership works.

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago