Skip to content

Commit bd9e6e5

Browse files
Merge pull request #715 from neelshah2409/main
Loan Calculator
2 parents 202e32d + e9e0b9d commit bd9e6e5

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed
5.27 KB
Loading
4.89 KB
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Loan Calculator
2+
3+
## Aim
4+
5+
To make a Loan calculator
6+
7+
## Purpose
8+
9+
For calculating the monthly repay and annual repay of loan amount in an easier manner.
10+
11+
## Short description of package/script
12+
- Here using the tkinter we had made an gui script where we ask the user their rate of interest and the amount of loan and duration and from that we give their repay amount, so it will be easier for a bank employeer and customer both to get a loan at the cheapest rate.
13+
- List out the libraries imported- >tkinter
14+
15+
16+
## Workflow of the Project
17+
18+
After running the script the gui application will pop and asks the user about rate of interest and the amount of loan and duration and will give repay amount as output.
19+
20+
21+
## Setup instructions
22+
23+
Firstly install tkinter library and then run the script so the gui application will pop and asks the user about rate of interest and the amount of loan and duration and will give repay amount as output.
24+
25+
26+
27+
## Output
28+
29+
![image](Images/output_1(loan).png)
30+
![image](Images/output_2(loan).png)
31+
32+
33+
## Author(s)
34+
35+
Neel Shah
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Import TKinter Module
2+
from tkinter import * # (*) Imports whole module
3+
4+
# Create a user defined class named: LoanCalculator which holds it's own
5+
# data members and member functions.
6+
7+
class LoanCalculator:
8+
def __init__(self): #Special method in Python Class-Constructor of a Python Class
9+
window = Tk() #Creates a window to house the calculator bits
10+
window.title("Loan Calculator") # sets the title
11+
window.configure(background = "light green") # sets bg color for window
12+
13+
# Create input boxes: Label function creates a display box to take input
14+
# The grid method gives it a table like structure
15+
#Widgets are centered by default.
16+
Label(window, font='Helvetica 12 bold',bg ="light green",text="Annual Interest Rate").grid(row=1,column=1, sticky=W)
17+
Label(window, font='Helvetica 12 bold',bg ="light green",text="Number of Years").grid(row=2,column=1, sticky=W)
18+
Label(window, font='Helvetica 12 bold',bg ="light green",text="Loan Amount").grid(row=3,column=1, sticky=W)
19+
Label(window, font='Helvetica 12 bold',bg ="light green", text="Monthly Payment").grid(row=4,column=1, sticky=W)
20+
Label(window, font='Helvetica 12 bold',bg ="light green",text="Total Payment").grid(row=5,column=1, sticky=W)
21+
22+
# Create objects: first 3 objects to take inputs using entry() function
23+
24+
self.annualInterestRateVar = StringVar()
25+
Entry(window, textvariable=self.annualInterestRateVar,justify=RIGHT).grid(row=1, column=2)
26+
27+
self.numberofYearsVar = StringVar()
28+
Entry(window, textvariable=self.numberofYearsVar,justify=RIGHT).grid(row=2, column=2)
29+
30+
self.loanAmountVar = StringVar()
31+
Entry(window, textvariable=self.loanAmountVar,justify=RIGHT).grid(row=3, column=2)
32+
33+
self.monthlyPaymentVar = StringVar()
34+
lblMonthlyPayment= Label(window,font='Helvetica 12 bold',bg ="light green", textvariable=self.monthlyPaymentVar).grid(row=4,column=2, sticky=E)
35+
36+
self.totalPaymentVar = StringVar()
37+
lblTotalPayment= Label(window,font='Helvetica 12 bold',bg ="light green", textvariable=self.totalPaymentVar).grid(row=5,column=2, sticky=E)
38+
39+
# Create button to calculate payment. When button is clicked it will call the compute payment function
40+
41+
btComputePayment = Button(window, text="Compute Payment",bg="red",fg="white",font='Helvetica 14 bold', command=self.computePayment).grid(row=6, column=2, sticky=E)
42+
btClear = Button(window, text="Clear",bg="blue",fg="white",font='Helvetica 14 bold', command=self.delete_all).grid(row=6, column=8, padx=20,pady=20 ,sticky=E)
43+
44+
window.mainloop() # The mainloop () function is used to run the application program.
45+
46+
# Create function to compute total payment
47+
48+
def computePayment(self):
49+
monthlyPayment = self.getMonthlyPayment(
50+
float(self.loanAmountVar.get()),
51+
float(self.annualInterestRateVar.get()) / 1200 ,
52+
int(self.numberofYearsVar.get()))
53+
54+
55+
self.monthlyPaymentVar.set(format(monthlyPayment, '10.2f'))
56+
totalPayment = float(self.monthlyPaymentVar.get()) * 12 \
57+
* int(self.numberofYearsVar.get())
58+
59+
self.totalPaymentVar.set(format(totalPayment, '10.2f'))
60+
61+
62+
def getMonthlyPayment(self,loanAmount,monthlyInterestRate,numberofYears):
63+
monthlyPayment = loanAmount * monthlyInterestRate / (1-1/(1 + monthlyInterestRate)** (numberofYears * 12 ))
64+
return monthlyPayment
65+
66+
67+
def delete_all(self) :
68+
self.monthlyPaymentVar.set("")
69+
self.loanAmountVar.set("")
70+
self.annualInterestRateVar.set("")
71+
self.numberofYearsVar.set("")
72+
self.totalPaymentVar.set("")
73+
74+
75+
76+
77+
# Call the class to run the program
78+
79+
LoanCalculator()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Libraries used: tkinter

0 commit comments

Comments
 (0)