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
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
Comments
Leave a comment