hi everyone, following is a part of my assignment and your help will deeply appreciated. Thank you, I'm a complete newbie at python.
q) each month should:
Calculate the monthly interest payment by multiplying the monthly interest rate, as a fraction, by the remaining principal.

Determine the amount remaining to be paid against the principal by subtracting the interest payment from the monthly payment amount
Reduce the principal by the amount calculated above.
Add the monthly interest to the running sum for total interest paid.
Add the monthly payment to the running sum of the monthly payments.
Check to see if this is the 12th month and the user has a nonzero anniversary payment percentage. If so, calculate the anniversary payment and subtract the entire amount of this payment from the principal. Add the payment amount to the running sum of total anniversary payments. Display the anniversary payment, if made.
Display the month and the remaining principal.
following is my messed up code, really need help cleaning this up. Thanks:
# This program calculates a monthly mortgage payment and the total interest
# paid for usersupplied values of the interest rate, principal and term.
def main():
# Obtain input parameters from the user and check for legality of each
# Get payment term and form loop to meet condition:
paymentTerm = int(input("Enter payment term in years: "))
while paymentTerm < 1 or paymentTerm > 30:
print("Payment term is not legal. Exiting program!")
paymentTerm = int(input("Enter payment term in years:"))
# Get annual interest %:
annualInterestPercent = float(input("Enter annual interest rate as %: "))
while annualInterestPercent < 1 or annualInterestPercent >10:
print("Annual interest rate is not legal. Exiting Program!")
annualInterestPercent = float(input("Enter annual interest rate as %:"))
# Get Principal amount and form loop to meet condition:
principal = float(input("Enter principal amount in $: "))
while principal < 1000 or principal > 500000:
print("Principal amount is not legal. Exiting program!")
principal = float(input("Enter Principal amount in $:"))
# Get anniversary payment %:
anniversaryPaymentPercent = float(input("Enter the anniversary payment percentage:"))
while anniversaryPaymentPercent < 0 or anniversaryPaymentPercent > 10:
print ("This is not legal. Exiting Program!")
anniversaryPaymentPercent = float(input("Enter the anniversary payment percentage:"))
# Calculate the monthly payment, total interest and anniversary payment:
termInMonths = 12 * paymentTerm
monthlyInterestRate = annualInterestPercent / 1200
monthlyPayment = principal * monthlyInterestRate / (1  (1 + monthlyInterestRate) ** termInMonths)
totalInterest = termInMonths * monthlyPayment  principal
anniversaryPayment = monthlyPayment * anniversaryPaymentPercent/100
principle_after_monthlyPayment = principal  monthlyPayment
monthly_interestPayment = monthlyInterestRate * principle_after_monthlyPayment
total_monthlyPayment = monthlyPayment  monthly_interestPayment
#Display the results
print("Monthly payment is ${0:.2f}".format(monthlyPayment))
#Ask how to stop when principle reaches 0 and how the principle will change..don't understand the "running sum concept at all"
month = 1
while principal > 0:
# monthly calculations:
month = month+1
print(month)
print(principle_after_monthlyPayment)
if anniversaryPaymentPercent > 0 and month%12==0:
print("Anniversary payment is",format(anniversaryPayment, '.2f'))
print("principal is", format(principle_after_monthlyPayment))
#print("Total interest paid is ${0:.2f}".format(totalInterest))
#print("Total monthly payment is ",format(total_monthlyPayment, '.2f'))
main()
Edited 3 Years Ago by pyTony: fixed formating