【发布时间】:2023-03-30 16:49:01
【问题描述】:
我有这个简单的摄氏到华氏代码。我无法创建要输出的 10 天列表。我可以输入一个输入,它给我华氏温度,但我不知道如何输入 10 天的列表以输出计算以及它是凉爽还是温暖。
tmp = int(input("Input the temperature you like to convert from Celsius to Fahrenheit? (e.g.,10) : "))
lst = [tmp]
i = 0
for i in range(len(lst)):
lst[i] = (lst[i] * 1.8) + 32
print(lst, "This is the fahrenheit temps")
if tmp < 0:
print('Freezing weather.\n')
elif tmp < 10:
print('Very cold weather.\n')
elif tmp < 20:
print('Cool weather\n')
elif tmp < 30:
print('Normal temps.\n')
elif tmp < 40:
print("It's hot outside.\n")
else:
print("You should properly stay inside")
【问题讨论】:
-
您是否会说您面临的问题更多地与传递列表作为输入有关,而与您期望温度数据的事实关系不大?如果是这样,我建议您编辑问题的标题以反映这一点
-
@PaulH 谢谢。我就是这么做的。
-
我给你个提示:
"23,25,12,56".split() -
提示 2:
str.split()返回 字符串 列表。你需要它们是数字。