【发布时间】:2016-12-08 00:53:02
【问题描述】:
我正在编写一个从另一个程序导入函数的简单程序。它基本上将华氏温度转换为摄氏温度,反之亦然,具体取决于您提供的输入类型。这是主程序的代码:
temp = int(input('What is the temperature? '))
print('Is this temperature in fahrenheit or celsius?')
system = int(input('Please put 1 for Fahrenheit and 2 for Celsius: '))
if system == 1:
from tempconvert import celsius
elif system == 2:
from tempconvert import fahrenheit
else:
print('I dont understand.')
下面是导入函数的程序代码:
def fahrenheit():
fahrenheit = temp * 1.8 + 32
def celsius():
celcius = temp - 32
celsius = celcius / 1.8
当我去做的时候,它会接受我输入的温度,它会接受华氏和摄氏之间的区别。但是它会说导入函数中的temp 没有定义。但我认为它将由主程序定义。因此,欢迎任何有关如何解决此问题的建议,因为我被困住了。
【问题讨论】:
标签: python function python-3.x import undefined