In: Computer Science
MUST BE PYTHON 3
Instructions: The following programming problem can be solved by a program that performs three basic tasks (Input Data, Process Data, Output Results) along with selection and repetition coding techniques.
Problem Statement
A finance company provides loans for motorcycles at different rates depending on how much the total loan amount is and how many payments will be made on the loan. Using the information in the table below, write a program that will calculate the monthly payment based on user inputs of loan amount and number of monthly payments. The user will NOT input the percentage rate, as this will be determined by the program code based on user input of loan amount and number of payments. The output will display the loan amount, the number of payments, monthly payments and the interest rate of the loan.
Amount of Loan | # of Payments | Interest Rate Applied |
---|---|---|
$500 - $ 2,500 | 6-12 | 8% |
13-36 | 10% | |
37-48 | 12% | |
$2,501 - $10,000 | 6-12 | 7% |
13-36 | 8% | |
37-48 | 6% | |
$10,001 or above | 6-12 | 5% |
13-36 | 6% | |
37-48 | 7% |
If the user enters data that is "out of bounds" (loan amount/number
of payments below or above minimum/maximum in the table), display
an error message explaining the situation to the user and ask for
the loan amount or number of payments (whichever one was out of
bounds) again. Message Example: "We do not finance loans below
$500."
You MUST use Modular Programming techniques by using functions in your program. Your "main" module should not be very large.
Other Requirements:
Submission Instructions:
def print_all(amount,no_of_payments,payment,rate):
headers=["Loan Amount","Number of Payments","Monthly Payments","Interest Rate"]
data=[[amount,no_of_payments,payment,rate]]
print (tabulate(data, headers))
def MonthlyPayment(amount,no_of_payments):
if amount<500:
print("We do not finance loans below $500.")
return 0
elif no_of_payments<6 or no_of_payments>48:
print("We do not finance loans for this period.")
return 0
else:
if amount>=500 and amount<=2500:
if no_of_payments>=6 and no_of_payments<=12:
rate=8
elif no_of_payments>=13 and no_of_payments<=36:
rate=10
elif no_of_payments>=6 and no_of_payments<=12:
rate=12
elif amount>2500 and amount<=10000:
if no_of_payments>=6 and no_of_payments<=12:
rate=7
elif no_of_payments>=13 and no_of_payments<=36:
rate=8
elif no_of_payments>=6 and no_of_payments<=12:
rate=6
else:
if no_of_payments>=6 and no_of_payments<=12:
rate=5
elif no_of_payments>=13 and no_of_payments<=36:
rate=6
elif no_of_payments>=6 and no_of_payments<=12:
rate=7
payment=round(((rate*amount)/(1-((1+(rate/100))**-no_of_payments)))/100,2)
print_all(amount,no_of_payments,payment,rate)
#Main Function
#enhanced the program for running it the no of times user wants it to run
from tabulate import tabulate
n=int(input("Enter the number of customers:"))
for i in range(n):
amount=int(input("Enter the loan amount:"))
no_of_payments=int(input("Enter the number of monthly payments:"))
MonthlyPayment(amount,no_of_payments)
OUTPUT: