数字应该是右对齐的。如何?

时间:2017-11-13 10:10:20

标签: python-3.x right-align

我正在尝试使所有数字右对齐,这是我的代码:

r=int(input('How many rows do you want?'))
while r<=0 :
    print('This value is not suitable')
    r=int(input('How many rows do you want?'))
c=int(input('How many columns do you want?'))
while c<=0 :
    print('This value is not suitable')
    c=int(input('How many columns do you want?'))

largest = (len(str(r**c)))
for i in range(1, r+1):
    for y in range(1, c+1):
        number = i**y
        tarp = ' ' * ((largest - len(str(number))))
        print(number, end = tarp) 
    print()

0 个答案:

没有答案