我有一个简单的摄氏到华氏的代码。我在创建要输出的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")
好吧,我根据你的需要重新编写了你的代码
还有一件事……用逗号(,)来分隔你的输入
一种方法是将不同的temp分离到不同的输入变量中,并将它们以实物形式附加到列表中,然后使用函数遍历该列表
像这样:
相关问题 更多 >
编程相关推荐