Python Program: Calculating Loan Payments for a Finance Company

Verified

Added on  2022/08/12

|9
|1328
|35
Homework Assignment
AI Summary
This assignment presents a Python program designed to calculate loan payments for a finance company specializing in motorcycle loans. The program takes user inputs for the loan amount and the number of monthly payments, then determines the applicable interest rate based on a predefined table. It then calculates and displays the monthly payment, total loan amount, and the applied interest rate. The program includes error handling to validate user inputs, ensuring they fall within the specified loan amount and payment ranges. The code is structured using functions for modularity and reusability, making it easier to understand and maintain. The document includes an introduction to Python, a discussion of the program's functionality, a conclusion summarizing the findings, references, and the complete Python code in the appendix.
Document Page
Running head: PYTHON PROGRAMMING
Python Programming
Student name:
Student ID:
University Name:
Paper Code:
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
2Python Programming
Table of Contents
Introduction................................................................................................................................3
Discussion..................................................................................................................................3
Conclusion..................................................................................................................................5
References..................................................................................................................................6
Appendix....................................................................................................................................7
Document Page
3Python Programming
Introduction
Python is one of the most popular and fastest growing programming language
nowadays. Python is considered to be an interpreter, also an object oriented language also
python is considered to be a high level language with having dynamic semantics (Guzdial,
Mark and Barbara Ericson, 2016). Also the data structure used in python are combined with
dynamic typing and also dynamic binding which eventually makes it an attractive for Rapid
Application Development. Python has a very simple syntax which eventually reduces the cost
of the program maintenance where such languages or technologies are used (Perkel and
Jeffrey, 2015). Python has a great feature which includes packages and modules which helps
grealy in code reusability and program modularity (Langtangen and Petter, 2014). Python has
different built-in libraries also varieties of library and packages which makes it easier for any
programmer to use these without any problems
The analysis is based on loan based company where a finance company provides loan
for motorcycle at different rates depending on how much the total loan amount is and how
many payments will be made on the loan. The main aim of the program is to calculate the
total payable amount by the customer including the interest to the finance company.
Discussion
Python programming are more flexible with function. Also using function it is more
convenient to write code with ease as function made calling easier (Schneider and David,
2015). Basically function is something a block of code that performs specific task only.
Functions are called from main function multiple times to do specific tasks only. Modular
Programming techniques is done by using functions in program (Lutz and Mark, 2013).
Function reduces complexity of the program. Some of the major advantages of using
functions are reuse of code, decomposing complex problems into a simple manner, hiding
Document Page
4Python Programming
information, optimizing duplicity of codes and also improving the code clarity with
appropriate writing of codes.
The program has been built using function. The program started with the input from
the user, the loan amount is been taken as input from the user and the total number of
payment the customer will need to repay the loan. These are the main two inputs needed for
the program. And if the user enters data which is "out of bounds" (loan amount/number of
payments below or above minimum/maximum in the table), then it will 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.
The below table shows the loan amount details with the total number of days to repay
the loan and the interest rate that will be charged depending upon the previous two factors.
Problem Statement
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%
Table 1
The payment is been calculated depending on some formula. The formula is listed below for
the calculation-
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
5Python Programming
From the equation it can be said that the PV and n are the parameters or the inputs
from the user. And according to these values the rate is been decided and at the end the P
which is the payment for the customer is been calculated accordingly.
A sample of the calculation has been shown below for proper understanding of the
calculation-
Let PV = $5000 and the number of payment be = 15
Thus from the table 1 it can be said that the interest rate will be 8%, hence the customer have
to pay an extra of $584.15.
Hence the total amount the customer have to pay as a whole is $5,584.15. And for 15 total
number of payments the customer have to pay $372.28 each for 15 payments.
Conclusion
From the above calculation and understanding it can be concluded that different banks
and finance company can have their individual formulas to calculate the total payable
amount. Also function plays a crucial role for reliability of code and proper understanding as
function makes lot easier to call a particular set of module with different parameters for same
task.
Document Page
6Python Programming
References
Guzdial, Mark, and Barbara Ericson. Introduction to computing and programming in python.
Pearson, 2016.
Langtangen, Hans Petter. A primer on scientific programming with Python. Vol. 6. Springer,
2014.
Lutz, Mark. Learning python: Powerful object-oriented programming. " O'Reilly Media,
Inc.", 2013.
Perkel, Jeffrey M. "Programming: pick up Python." Nature News 518.7537 (2015): 125.
Schneider, David I. An Introduction to Programming Using Python. Pearson, 2015.
Document Page
7Python Programming
Appendix
def main():
while True:
loan=int(input("Enter the Loan Amount: $"))
if loan <500:
print("\nWe do not finance loans below $500")
continue
days=int(input("\nEnter the number of monthly payments (Between 6 to 48): "))
if days<6 or days>48:
print("\nThe entered number is either below 6 or above 48 which we donot
serve ! ! !")
continue
condition(loan,days)
con=input("\nWant to calculate more?(y/n): ")
if con.lower()=="y":
continue
else:
break
def condition(loan,days):
if loan >=500 and loan <=2500:
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
8Python Programming
if days>=6 and days<=12:
calculation(loan,days,0.08)
elif days>=13 and days<=36:
calculation(loan,days,0.10)
else:
calculation(loan,days,0.12)
elif loan >=2501 and loan <=10000:
if days>=6 and days<=12:
calculation(loan,days,0.07)
elif days>=13 and days<=36:
calculation(loan,days,0.08)
else:
calculation(loan,days,0.06)
else:
if days>=6 and days<=12:
calculation(loan,days,0.05)
elif days>=13 and days<=36:
calculation(loan,days,0.06)
else:
calculation(loan,days,0.07)
Document Page
9Python Programming
def calculation(l,p,r):
pay=(r*l)/(1-(1+r)**(-p))
print("\n-----------------------*** LOAN SUMMARY ***-----------------------")
print(f"\nThe loan amount is: ${l}")
print(f"\nThe number of payments is: {p}")
print(f"\nMonthly Payment: ${round((l+pay)/p,2)}")
print(f"\nThe interest loan of the loan is: {int(r*100)}%")
if __name__== "__main__":
main()
chevron_up_icon
1 out of 9
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]