【发布时间】:2021-09-09 04:13:36
【问题描述】:
我正在尝试打印一个看起来像这样没有额外空格的表格,并且用户输入了下限(在本例 4 中)和上限(在本例中 8)。
#Get the inputs
input3=int(float(input("Give me the lower bound: ")))
input4=int(float(input("Give me the upper bound: ")))
#create a loop to multiply the upper and lower bounds
multiplication_table_str= ""
for i in range(input3,input4+1):
multiplication_table_str+= str(i) + ": "
for x in range(input3,input4+1):
multiplication_table_str+=str(i*x)+"\t"
multiplication_table_str+="\n"
print(multiplication_table_str)
我所拥有的输出正确,但数字内部有一个额外的缩进,我想摆脱它,但我不知道如何。我希望它看起来像这样:
4: 16 20 24 28 32
5: 20 25 30 35 40
6: 24 30 36 42 48
7: 28 35 42 49 56
8: 32 40 48 56 64
【问题讨论】:
-
只需使用空格 (
" ") 而不是制表符 ("\t")。
标签: python coding-style