Answer to Question #300960 in Python for bhanu

Question #300960

bulb states pattern

bulb states pattern program contain input is a single line containing a positive integer n representing the number of rooms in the building and the output should contain n lines , each line containing the state of the bulb in the room numbered from 1 to n in the form of 0 and 1.

example:

input: 5


1
Expert's answer
2022-02-22T01:10:22-0500
'''
bulb states pattern
    bulb states pattern program contain input is a single line containing
    a positive integer n representing the number of rooms in the building
    and the output should contain n lines , each line containing the state
    of the bulb in the room numbered from 1 to n in the form of 0 and 1.
'''


   
n = int(input("Enter the no. of rooms: "))
if(n>0):
    for r in range(1,n+1):
        print("N =",r,":",bin(r).replace("0b", ""))




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