My Python First Project🐍

My Python First Project🐍

This article describes my first python project.🤩

No alt text provided for this image

Building projects helped me bring together everything I was learning. Once I started building projects, I immediately felt like I was making more progress.

Project-based learning is also the philosophy behind our teaching method using Python. Why? Because time and time again, we’ve seen that it works!

But it can be difficult to build Python projects for beginners but actually it was very easy form me as i was doing it very first time . So now directly moving towards my pyhton project explaination part.

Simple EMI Calculator in Python

There you go, you get to see my first python project. It’s a Simple EMI Calculator. This EMI calculator had these basic steps.


# 1. import tkinter module
# 2. creating class
# 3. creating the constructer
# 4. create application window
# 5. create title for the app window
# 6. set bg color for app window
# 7. add lables for input feild        


This EMI calculator takes the input from the user and then gives the monthly installment of that the user.

Here is my all code what i did in this project .

from tkinter import *

class LoanCalculator:
    def __init__(self):
        window=Tk()
        window.title("Loan calculator")
        window.configure(background='#96DED1')
        Label(window,font='Aerial 18 bold',bg='#96DED1',text='Interest     Rate').grid(row=1,column=1,sticky=W)
        Label(window, font='Aerial 18 bold',bg='#96DED1', text='Number of Years').grid(row=2, column=1, sticky=W)
        Label(window, font='Aerial 18 bold',bg='#96DED1', text='Loan Amount').grid(row=3, column=1, sticky=W)
        Label(window, font='Aerial 18 bold',bg='#96DED1', text='Monthly Payment').grid(row=4, column=1, sticky=W)
        Label(window, font='Aerial 18 bold',bg='#96DED1', text='Total Payment').grid(row=5, column=1, sticky=W)


# part=2
# add label widgets
# create objects to take user import & display values
        self.AnnualRateInterestVar = StringVar()
        Entry(window,textvariable=self.AnnualRateInterestVar,font=('calibre',10, 'bold'),justify=RIGHT).grid(row=1,column=2)

        self.numberOfYearsVar = StringVar()
        Entry(window, textvariable=self.numberOfYearsVar,font=('calibre',10, 'bold'), justify=RIGHT).grid(row=2, column=2)

        self.loanAmountVar = StringVar()
        Entry(window, textvariable=self.loanAmountVar,font=('calibre',10, 'bold'), justify=RIGHT).grid(row=3, column=2)

        self.monthlyPaymentVar=StringVar()
        lblMonthlyPayment = Label(window,font='Helvetica 12 bold',bg='#E6C97D',textvariable=self.monthlyPaymentVar).grid(row=4,column=2,sticky=E)

        self.totalPaymentVar = StringVar()
        lblTotalPayment = Label(window, font='Helvetica 12 bold', bg='light green',textvariable=self.totalPaymentVar).grid(row=5, column=2, sticky=E)

# Part=3
# 1. Create to button to calculator values
# 2. Create a button to clear user input and values entered by user.

        btcomputePayment = Button(window,text='Calculate Payment',bg='red',fg='white',font='Helvetica 14 bold',command=self.computePayment).grid(row=6, column=2,sticky=E)

        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)

        window.mainloop()

    def computePayment(self):
        monthlyPayment = self.getMonthlyPayment(
            float(self.loanAmountVar.get()),
            float(self.AnnualRateInterestVar.get())/1200,
            int(self.numberOfYearsVar.get()))

        self.monthlyPaymentVar.set(format(monthlyPayment,'10.2f'))
        totalPayment = float(self.monthlyPaymentVar.get())*12*int(self.numberOfYearsVar.get())

        self.totalPaymentVar.set(format(totalPayment,'10.2f'))

    def getMonthlyPayment(self,loanAmount,monthlyInterestRate,numberOfYears):
        monthlyPayment = loanAmount * monthlyInterestRate/(1-1/(1+monthlyInterestRate)**(numberOfYears*12))
        return monthlyPayment

    def delete_all(self):
        self.monthlyPaymentVar.set("")
        self.loanAmountVar.set("")
        self.AnnualRateInterestVar.set("")
        self.numberOfYearsVar.set("")
        self.totalPaymentVar.set("")
        

Here is the final output of my program.😍😍😍

No alt text provided for this image


So it was all about my first python project i hope you enjoyed it 🤩🤩🤩.

thanks for visiting🤗🤗🤗


...................................................!Thank you! ..............................................................


NITISH CHAUDHARY




To view or add a comment, sign in

Others also viewed

Explore content categories