如何解决温度换算表
我需要编写一个程序,在表格中显示摄氏度到华氏温度的转换。
问题-在列表中打印特定索引的正确方法是什么。 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('-------------------')
解决方法
通过括号()调用函数。用方括号[0]来访问索引:
print(tbl[0] + ':\t\t',tbl2[0])
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。