Python triangle quest, arithmetical operation inside print

前端 未结 2 907
迷失自我
迷失自我 2021-01-07 06:23

I try solve this problem I know that, I can do that like

for i in range(1,input()): 
    print int(str(i)*i)

It works, but I can\'t use str

2条回答
  •  长发绾君心
    2021-01-07 06:47

    I tried doing it this way (notice I took floor division here):

    for i in range(1,int(input())):
        print(i*((10**i)//9))
    

    for input 5, it yields:

    1
    22
    333
    4444
    

提交回复
热议问题