Binary Burj Khalifa,Hackerranksolution,by Codexritik






Binary Burj Khalifa


Write the program to create building structure like the burj khaleefa using binary number
Input Format
standard input for the height
Constraints
0>=height and height<=500
Output Format
pattern with binary number
Sample Input 0
10
Sample Output 0
   0 
   1 
  10 
  11 
 100 
 101 
 110 
 111 
1000 
1001 
1010
Sample Input 1
15
Sample Output 1
   0 
   1 
  10 
  11 
 100 
 101 
 110 
 111 
1000 
1001 
1010 
1011 
1100 
1101 
1110 
1111

Solution;
n=int(input(""))
l=len(str(bin(n)))-2
for k in range(n+1):
    k=bin(k)
    k=str(k)[2:]
    p=len(k)
    print(" "*(l-p)+k)
Binary Burj Khalifa,Hackerranksolution,by Codexritik Binary Burj Khalifa,Hackerranksolution,by Codexritik Reviewed by CodexRitik on February 08, 2020 Rating: 5

No comments:

Powered by Blogger.