简体   繁体   中英

I'm new to python and I feel like I am doing this code the long way but I am stuck at what to do next

Create a program. The program lets the user enter the loan amount and loan period in number of years. The program will then display the monthly and total payments for each annual interest rate starting from 4 to 8 in increments of 1.

Be sure to define a function to calculate the values and print the table displaying the interest rate in the first column, the monthly payment in the second column, and the total payment in the third column. Your program should not allow the user to enter negative amounts for the loan amount and the loan period.

Once the table has been displayed the user should be prompted as to whether they wish to enter another loan amount and loan period.

Here is what I have so far:

import math

def main():

    loan_amount = input("Enter The amount of the loan : ")
    loanYears = input("Enter The number of years of the loan: ")

    print "Interest Rate"       "Monthly Payment"        "Total Payment"
    print      "4%",              monthly_payment,          total_payment
    print      "5%",              monthly_payment2,         total_payment2
    print      "6%",              monthly_payment3,         total_payment3
    print      "7%",              monthly_payment4,         total_payment4
    print      "8%",              monthly_payment5,         total_payment5

def payment():
    monthly_rate = (4/100.00)/ 12
    monthly_rate2 = (5/100.00)/ 12
    monthly_rate3 = (6/100.00)/ 12
    monthly_rate4 = (7/100.00)/ 12
    monthly_rate5 = (8/100.00)/ 12

    monthlyPayment = loan_amount * monthly_rate / (1 - math.pow(1/(1 + monthly_rate)loanYears * 12))
    monthlyPayment2 = loan_amount * monthly_rate2 / (1 - math.pow(1/(1 + monthly_rate2)loanYears * 12))
    monthlyPayment3 = loan_amount * monthly_rate3 / (1 - math.pow(1/(1 + monthly_rate3)loanYears * 12))
    monthlyPayment4 = loan_amount * monthly_rate4 / (1 - math.pow(1/(1 + monthly_rate4)loanYears * 12))
    monthlyPayment5 = loan_amount * monthly_rate5 / (1 - math.pow(1/(1 + monthly_rate5)loanYears * 12))
    total_payment = monthly_payment * loan_years * 12
    total_payment2 = monthly_payment2 * loan_years * 12
    total_payment3 = monthly_payment3 * loan_years * 12
    total_payment4 = monthly_payment4 * loan_years * 12
    total_payment5 = monthly_payment5 * loan_years * 12 


main()

Here is the error I receive

Your error is pointing out the problem: (1 + monthly_rate)loanYears is not legal syntax. Probably related to the problem where math.pow is being called with one argument, when it requires two.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM