【发布时间】:2016-04-06 23:32:45
【问题描述】:
我制作的程序有点问题。我不太确定问题是什么。但是,我想不出要寻找什么来解决问题。既然是这种情况,如果这是一个重复的问题,我提前道歉。
# convert.py
# A program to convert Celsius temps to Fahrenheit
def main():
print("Hello", end=" ")
print("this program will convert any 5 different celsius temperatures to fahrenheit.")
c1, c2, c3, c4, c5 = eval(input("Please enter 5 different celsius temperatures seperated by commas: "))
print(c1, c2, c3, c4, c5)
for i in range(5):
c = ("c" + str(i + 1))
print(c)
fahrenheit = 9/5 * c + 32
print("The temperature is", fahrenheit, "degrees Fahrenheit.")
input("The program has now finished press enter when done: ")
main()
在第一个循环的华氏赋值语句之前,该程序运行良好。我确信问题涉及变量以及我分配它们的最可能不正确的方式。因此,如果有人能指出我做错了什么以及为什么它不起作用,我将不胜感激。
【问题讨论】:
-
100 次中有 99 次,如果您尝试动态访问变量,那么您做错了。将输入保留为元组 (
temperatures = eval(input(...))) 并对其进行迭代 (for temperature in temperatues:)
标签: python variables python-3.x variable-assignment