【发布时间】:2021-06-21 16:47:15
【问题描述】:
我刚刚从手册中复制了这段代码,但是当我编写它时,当 kph > 100 时,显示列之间的间距会变大。
# This program converts the speeds 60 kph
# Throug 130 kph ( in 10 kph increments)
# to mph.
START_SPEED = 60 # Starting Speed
END_SPEED = 131 # Ending speed
INCREMENT = 10 # Increment
CONVERSION_FACTOR = 0.6214 # Conversion Factor
# Print the table headings.
print("KPH\tMPH")
print("--------")
for kph in range(60, 131, 10):
mph = kph * CONVERSION_FACTOR
print(kph, "\t", format(mph, ".1f"))
当我编写这段代码时,我得到:
KPH MPH
--------
60 37.3
70 43.5
80 49.7
90 55.9
100 62.1
110 68.4
120 74.6
130 80.8
Process finished with exit code 0
如何使两列之间的空间均匀?
【问题讨论】:
标签: python formatting spacing