自己的模块
作者:
莫烦
2016-11-03
编辑:
自建一个模块 ¶
这里和视频有点差别,我自己写了另外一个模块,是计算五年复利本息的模块,代码如下:模块写好后保存在默认文件夹:balance.py
d=float(input('Please enter what is your initial balance: \n'))
p=float(input('Please input what is the interest rate (as a number): \n'))
d=float(d+d*(p/100))
year=1
while year<=5:
d=float(d+d*p/100)
print('Your new balance after year:',year,'is',d)
year=year+1
print('your final year is',d)
调用自己的模块 ¶
新开一个脚本,import balance
import balance
""""
Please enter what is your initial balance:
50000 # 手动输入我的本金
Please input what is the interest rate (as a number):
2.3 #手动输入我的银行利息
Your new balance after year: 1 is 52326.45
Your new balance after year: 2 is 53529.95834999999
Your new balance after year: 3 is 54761.14739204999
Your new balance after year: 4 is 56020.653782067144
Your new balance after year: 5 is 57309.12881905469
your final year is 57309.12881905469
""""
模块存储路径说明 ¶
在Mac系统中,下载的python模块会被存储到外部路径site-packages
,同样,我们自己建的模块也可以放到这个路径,最后不会影响到自建模块的调用。
降低知识传递的门槛
莫烦很常从互联网上学习知识,开源分享的人是我学习的榜样。 他们的行为也改变了我对教育的态度: 降低知识传递的门槛。 免费 奉献我的所学正是受这种态度的影响。 通过 【赞助莫烦】 能让我感到认同,我也更有理由坚持下去。
想当算法工程师拿高薪?转行AI无门道?莫烦也想祝你一臂之力,市面上机构繁杂, 经过莫烦的筛选,七月在线脱颖而出, 莫烦和他们合作,独家提供大额 【培训优惠券】, 让你更有机会接触丰富的教学资源、培训辅导体验, 祝你找/换工作/学习顺利~