我有以下python代码:
#This program converts the speeds 60 KPH
#through 130 KPH (in 10 kph increments)
#to MPH
#Global constants
START = 60
END = 131
INCREMENT = 10
CONVERSION_FACTOR = 0.6214
def main():
#Print the table headings
print('KPH\t\tMPH')
print('----------------')
#Print the speeds
for kph in range(START, END, INCREMENT):
mph = kph * CONVERSION_FACTOR
print(kph, '\t\t', format(mph, '.1f'))
#Call the main function
main()
Run Code Online (Sandbox Code Playgroud)
运行此代码我得到以下结果:
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
Run Code Online (Sandbox Code Playgroud)
如何正确对齐第二列,以便更正确地显示我的结果?
小智 11
使用格式规范迷你语言
"{:>10.3}".format(12.34)
Run Code Online (Sandbox Code Playgroud)
结果(_用于空格):
______12.3
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7337 次 |
| 最近记录: |