0

How to print the following pattern in python.

0 22 444 8888

13th Mar 2019, 8:49 PM
Aditya Anupam
Aditya Anupam - avatar
3 Respuestas
+ 2
c = 1 i = 1 print(i-1) while i < 8: c += 1 i *= 2 print(str(i)*c) #Or, to make it 6 lines like Jay Matthews' solution ;) c = [1,1] print(c[0]-1) while c[1] < 8: c[0] += 1 c[1] *= 2 print(str(c[1])*c[0])
13th Mar 2019, 11:26 PM
Peter Popoola
Peter Popoola - avatar
+ 2
Oh, great. Thanks, Jay Matthews! Got a shorter (5-liner) one, then: c,i = 1,1 while i < 9: print(str(i if i != 1 else i-1)*c) c += 1 i *= 2
13th Mar 2019, 11:37 PM
Peter Popoola
Peter Popoola - avatar
+ 2
[print(str(2**i*(i>0))*(i+1)) for i in range(4)]
14th Mar 2019, 12:30 AM
Diego
Diego - avatar