Menu

[Solved]Python Write Python Program Control Set 8 Lights Use Lights Variable Hold 8 Flags Numbered Q37049891

Python

Write a Python program to control a set of 8 lights. Use alights variable which will hold
8 flags numbered from 0 to 7, counting the position from right toleft.

The script should initialize a flags variable (lights) with alllights off
(lights = 0b00000000). Then an option menu should be presented toperform
8 tasks as follows:

  • 1 – Show status of All lights, see output below for option1
  • 2 – Show status of a single light, ask user which light andshow status ON or OFF
  • 3 – Turn ALL lights ON (lights = 0b11111111)
  • 4 – Turn ALL lights OFF (lights = 0b00000000)
  • 5 – Turn ON a single light, ask user which light and then setlight flag (bit) to 1
  • 6 – Turn OFF a single light, ask user which light and thenreset light flag (bit) to 0
  • 7 – Toggle a single light, ask user which light and then flipthe light flag (bit)
    • from ON to OFF .. OR .. OFF to ON (from 1 to 0 OR 0 to 1)
  • q – quit script and exit

NOTE:

  • options 1, 2: report the status of ONE or ALL light(s)(ON/OFF).
    NO light statuses are changed
  • options 3, 4: sets or resets the status of ALL lights (All ON.. OR .. All OFF)
  • options 5, 6, 7: at most changes the value of one light (onebit).

light status panel:

Light Number | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ————–|—–|—–|—–|—–|—–|—–|—–|—–| Status | OFF | OFF | OFF | OFF | OFF | OFF | OFF | OFF |

Expert Answer


Answer to Python Write a Python program to control a set of 8 lights. Use a lights variable which will hold 8 flags numbered from … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *