我正在计算每月支付多少钱以便在12个月内还清贷款。使用10美元作为增量。
Payment = 0
balance = float (1200)
interest = float (0.18)
MonthlyInt = interest/12.0
while balance > 0 :
Payment = Payment + 10
month = 0
while month < 12 and balance > 0:
IntPay = balance* MonthlyInt
balance += IntPay
balance -= Payment
month += 1
print Payment
正确的答案应该是110,为什么我要60岁?
答案 0 :(得分:3)
产生差异的主要因素是:
一些较小的python东西是:
float()
不需要0.18
这样的数字,它已经是一个浮动1200.
意味着该号码是一个浮点数,因此不需要float()
然后考虑这些事情:
Payment = 0
interest = 0.18
MonthlyInt = interest/12.0
balance = 1200.
while balance > 0 :
Payment = Payment + 10
month = 0
balance = 1200.
while month < 12 and balance > 0:
balance -= Payment
IntPay = balance* MonthlyInt
balance += IntPay
month += 1
print(Payment)
结果为110
。
答案 1 :(得分:1)
这是另一种方法。我尝试在MIT edx课程中使用Brians示例,并且无法在所有情况下都使用它。
这就是我做到的。
def lowestpayment(x,y):
""" x = total balance due
y = annual interest rate
Returns min payment needed to pay off debt in 1 year
"""
month = 0
balance = x
annualInterestRate = y
payment = 0
while balance > 0 and month <= 12:
month = 0
balance = x
payment += 10
balance = balance - payment
monthlyint = balance*annualInterestRate/12
balance += monthlyint
month += 1
if balance+(balance*annualInterestRate/12)*11-payment*12 <= 0:
return payment
print("Lowest Payment: ",lowestpayment(35,0.25))
答案 2 :(得分:0)
问..
<块引用>编写一个 Python 程序,在适当的提示下输入本金金额、利率和年数。找到简单的兴趣并按以下格式显示所有详细信息:
本金金额:卢比。 __________
利率:____%
年数:____
简单的兴趣:卢比。 __________
到期金额:卢比。 __________
答案::
# for input
p = float (input("ENTER PRINCIPLE AMOUNT : "))
r = float (input("ENTER RATE OF INTEREST : "))
y = float (input("ENTER NUMBER OF YEARS : "))
# SIMPLE INTEREST
si = (p * r * y)/100
# display
print("{0:25}: Rs. {1}".format("Principal Amount", p))
print("{0:25}: {1}".format("Rate Of Interest",r ),"%")
print("{0:25}: {1}".format("Number Of Years",y))
print("{0:25}: Rs. {1}".format("Simple Interest",si))
print("{0:25}: Rs. {1}".format("Maturity Amount",p + si))