【问题标题】:Temperature conversion Table [closed]温度换算表[关闭]
【发布时间】:2020-11-08 09:24:23
【问题描述】:

我需要编写一个程序,在表格中显示摄氏到华氏温度的转换。

问题 - 在列表中打印特定索引的正确方法是什么。 My attempt comes from the answer to a similar exercise outlined here。提前致谢。

这是我的代码

temp = range(0 , 101, 10)
tbl = []
tbl2 = []
for i in temp:
    cel = i
    tbl.append(cel)
    fah = (i * 9/5) + 32
    tbl2.append(fah)
    print(cel, fah)

print('Celsius\t\tFahrenheit')
print('-------------------')
print(tbl(0) + ':\t\t', tbl2(0))
print('-------------------')

这是我的输出

【问题讨论】:

  • print(str(tbl[0]) + ':\t\t', tbl2[0])

标签: python temperature


【解决方案1】:

函数用圆括号() 调用。使用括号[0]访问索引:

print(tbl[0] + ':\t\t', tbl2[0])

【讨论】:

    猜你喜欢
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    相关资源
    最近更新 更多