自建一个模块
我自己写了一个模块,关于贷款月供的模块,代码如下:模块写好后保存在默认文件夹:Meta.py
# -*- coding:utf-8 -*-
total = float(input("请输入贷款总额:"))
p = float(input('贷款年利率(比如5.88):'))
y = int(input('贷款年数:'))
type = input('输入1表示等额本金,0表示等额本息:')
#计算得出 月供
if type == 1:
i = 1
m = total/y/12 #每月需要支付的本金
while i <= y*12:
d = float(m + (total)*p/100/12)
print u'等额本金月供:'
print(d)
total = total - m
i += 1
elif type == 0:
d = float(total*p/100/12*(1+p/100/12)**(y*12)/((1+p/100/12)**(y*12)-1))
print u'等额本息:'
print(d)
else:
print u'无效的方式'
调用自己的模块
新开一个脚本,import Meta
import Meta
""""
请输入贷款总额:1000000
贷款年利率(比如5.88):5.88
贷款年数:30
输入1表示等额本金,0表示等额本息:0
等额本息:
5918.57358833
""""
模块存储路径说明
在Mac系统中,下载的python模块会被存储到外部路径site-packages
,同样,我们自己建的模块也可以放到这个路径,最后不会影响到自建模块的调用。