Answer to Question #288914 in Python for sai krishna

Question #288914

in a building there are n rooms numbered from 1 to n in each room there is a bulb that is initially open for the odd numbered rooms and off for the even numbered rooms before visiting a room, you will note the state of the bulb rooms before visiting a room you will note the state of the bulb when you leave a room the bulb is turned off if it is on and turned on if it numbered you then return to the station room and repeat the process for n times in python assignment


1
Expert's answer
2022-01-21T09:44:30-0500
n=int(input('Enter the number of rooms: '))
def light_bulb(n):
    for i in range(1,n+1):
        if i%2==1:
            print(" For room {}, the light is ON when entering and the light is OFF when out of the room".format(i))
        else:
            print("For room {}, the light is OFF when entering and the light is ON when out of the room".format(i))
light_bulb(n)
Enter the number of rooms: 4
 For room 1, the light is ON when entering and the light is OFF when out of the room
For room 2, the light is OFF when entering and the light is ON when out of the room
 For room 3, the light is ON when entering and the light is OFF when out of the room
For room 4, the light is OFF when entering and the light is ON when out of the room

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS