还是书上的练习题,第一次创作模块还蛮有意思的。纪念一下(~ ̄▽ ̄)~
首先建立模块
#this is the file "my_module.py"
#we're going to use it in another program
def c_to_f(celsius):
fahrenheit=celsius*9.0/5+32
return fahrenheit
然后在需要的时候调用这个模块
import my_module
celsius=float(input('Enter a temperature in Celsius:'))
fahrenheit=my_module.c_to_f(celsius)
print("That's",fahrenheit,"degrees Fahrenheit")
我们就可以在需要的时候导入这个模块,计算摄氏度转华氏度啦ヾ(๑╹◡╹)ノ"