0
How to print the following pattern in python.
0 22 444 8888
3 Respostas
+ 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])
+ 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
+ 2
[print(str(2**i*(i>0))*(i+1)) for i in range(4)]