错误解决:Type 'str' doesn't have excpected attribute '_sub_' less....This inspection detects type erros in function call expression. Due to dynamic and duck typing, this is possible in a limited but useful number of cases. Types of function paraments can be specified in docstrings or in Python 3 function annotations.
这个错误的原因是输入的数据是str字符串行,我们需要把输入的数据换成对应的数据类型。
存款贷款利率计算代码
import numpy as np
#存款利率采用复利计算,上个月的利率纳入下一个月的本金计算再下一个月的利率,第一个月不计算利率,一个月计算一次利率
def Bankrate(money,rate,moth):
money2=money
money1 = money * (1 + rate / 12)
for i in range(moth-1):
newmoney = money * (1 + rate / 1200) + money1
money = newmoney
print("每月存款",money2,"元")
print(moth,"月后")
print("存款总额",money,"元")
#return money
#采用终值计算每个月应支付多少
def SumGeometric(bmoney,brate,bmoth):#公比、次方
brate = brate / 12
a = 1 + brate
am=np.power(a,bmoth)
gsum=am*(a-1)/(am-1)
everymothmoney=bmoney*gsum
print("分期",bmoth, "月付款")
print( "每月付款", everymothmoney, "元")
print("最后总共付款->",everymothmoney*bmoth,"元")
#return everymothmoney
if __name__=="__main__":
deposit="存款"
loans="贷款"
inwords=input("存款或者贷款计算选择")
if (inwords==deposit):
money=input("请输入每月存款金额:")
moth=input("请输入存款几个月:")
rate=input("存款年利率:")
money=int(money)
moth=int(moth)
rate=float(rate)
Bankrate(money, rate, moth)
elif(inwords==loans):
bmoney=input("请输入贷款金额:")
bmoth=input("请输入分期(月)返款:")
brate=input("贷款年利率:")
bmoney=int(bmoney)
bmoth=int(bmoth)
brate=float(brate)
SumGeometric(bmoney, brate, bmoth)
else:
print("请重新输入选择")