0% found this document useful (0 votes)
33 views

Skanda Py

The document contains code for several Python programs: 1) A class to model employees with methods to accept employee details, search by ID, and display details. 2) Bank account and savings account classes with deposit, withdraw, balance methods and interest calculation. 3) A GUI to calculate compound interest by inputting principal, rate, years. 4) A GUI calculator program with number buttons and arithmetic operations.

Uploaded by

abhiram abhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Skanda Py

The document contains code for several Python programs: 1) A class to model employees with methods to accept employee details, search by ID, and display details. 2) Bank account and savings account classes with deposit, withdraw, balance methods and interest calculation. 3) A GUI to calculate compound interest by inputting principal, rate, years. 4) A GUI calculator program with number buttons and arithmetic operations.

Uploaded by

abhiram abhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

1. Program to create a class Employee with empno, name, depname, designation, age
and salary and perform the following function.
i) Accept details of N employees
ii) Search given employee using empno
iii) Display employee details in neat format.class emp:

class emp:
def __init__(self):
self.empno=None
self.empname=None
self.depname=None
self.sal=None
self.desg=None
self.age=None
def getemp(self):
print('enter id :',end=' ')
self.empno=(int(input()))
print('enter name:',end=' ')
self.empname=(input())
print("enter age:",end=' ')
self.age=(int(input()))
print("enter designation:",end=' ')
self.desg=(input())
print("enter department:",end=' ')
self.depname=(input())
print("enter the salary:",end=' ')
self.sal=(int(input()))
print("-"*10)
def dispemp(self):
print("*"*10)
print("emp no:",self.empno)
print(f"emp name:{self.empname}")
print(f"emp age:{self.age}")
print(f"emp designation:{self.desg}")
print(f"emp department:{self.depname}")
print(f"emp salary:{self.sal}")
print("*"*10)
def search(self,empno):
if empno==self.empno:
return True
else:
NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

return False
n=int(input("enter total no of employee: "))
l=list()
for i in range (n):
E=emp()
E.getemp()
l.append(E)
for empobj in l:
empobj.dispemp()
empid=int(input("enter id to be searched: "))
found=False
for empobj in l:
found=empobj.search(empid)
if(found):
empobj.dispemp()
break
if(not found):
print("employee not exist")

Output:
enter total no of employee: 2
enter id : 1001
enter name: skanda
enter age: 24
enter designation: manager
enter department: bank
enter the salary: 60000
----------
enter id : 1002
enter name: ram
enter age: 30
enter designation: co
enter department: bank
enter the salary: 90000
----------
**********
emp no: 1001
emp name:skanda
emp age:24
emp designation:manager
NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

emp department:bank
emp salary:60000
**********
**********
emp no: 1002
emp name:ram
emp age:30
emp designation:co
emp department:bank
emp salary:90000
**********
enter id to be searched: 1002
**********
emp no: 1002
emp name:ram
emp age:30
emp designation:co
emp department:bank
emp salary:90000
**********
NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

2. Write a program menu driven to create a BankAccount class. class should support
the following methods for i) Deposit ii) Withdraw iii) GetBalanace . Create a
subclass SavingsAccount class that behaves just like a BankAccount, but also has
an interest rate and a method that increases the balance by the appropriate amount
of interest.

class BankAccount:
def __init__(self,account_number,date_of_opening,balance,customer_name):
self.account_number=account_number
self.date_of_opening=date_of_opening
self.balance=balance
self.customer_name=customer_name
def deposit(self):
amount=float(input("enter the amount to deposit"))
self.balance+=amount
print(f"${amount}has been deposited in your account")
def withdraw(self):
amount=float(input("enter the amount to withdraw"))
if amount>self.balance:
print("insufficient balance")
else:
self.balance-=amount
print(f"${amount}has been withdrawn from your account")
def check_balance(self):
print(f"current balance is ${self.balance}")
def print_customer_details(self):
print("name:",self.customer_name)
print("account number:",self.account_number)
print("date of opening:",self.date_of_opening)
print(f"balance:${self.balance}\n")
class SavingsAccount(BankAccount):
def __init__ (self,account_number,date_of_opening,balance,customer_name):
super().__init__(account_number,date_of_opening,balance,customer_name)
def interest_rate(self):
int_rate=float(input("enter the interest rate:"))
self.balance=self.balance + self.balance*(int_rate/100)
print(f"after adding interest to your account , current balance in your account=$
{self.balance}")
acc_no_1=SavingsAccount(1234,"01-01-2023",1000,"skanda")
while(True):
print("1.to deposit")
NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

print("2.to withdraw")
print("3.to display")
print("4.to check balance")
print("5.to add interest")
print("6.to exit")
i=int(input("enter the choice:"))
if i==1:
acc_no_1.deposit()
elif i==2:
acc_no_1.withdraw()
elif i==3:
acc_no_1.print_customer_details()
elif i==4:
acc_no_1.check_balance()
elif i==5:
acc_no_1.interest_rate()
elif i==6:
break
else:
print("enter the correct choice")
output:
1.to deposit
2.to withdraw
3.to display
4.to check balance
5.to add interest
6.to exit
enter the choice:1
enter the amount to deposit25000
$25000.0has been deposited in your account
1.to deposit
2.to withdraw
3.to display
4.to check balance
5.to add interest
6.to exit
enter the choice:2
enter the amount to withdraw20000
$20000.0has been withdrawn from your account
1.to deposit
NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

2.to withdraw
3.to display
4.to check balance
5.to add interest
6.to exit
enter the choice:3
name: manoj
account number: 1234
date of opening: 01-01-2023
balance:$6000.0

1.to deposit
2.to withdraw
3.to display
4.to check balance
5.to add interest
6.to exit
enter the choice:4
current balance is $6000.0
1.to deposit
2.to withdraw
3.to display
4.to check balance
5.to add interest
6.to exit
enter the choice:5
enter the interest rate:5
after adding interest to your account , current balance in your account=$6300.0
NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

3. Create a GUI to input Principal amount, rate of interest and number of years,
Calculate Compound interest. When button submit is pressed Compound interest
should be displayed in a textbox. When clear button is pressed all contents should
be cleared.

from tkinter import*


def clear_all():
principle_field.delete(0,END)
rate_field.delete(0,END)
time_field.delete(0,END)
t1.delete("1.0",END)
principle_field.focus_set()

def calculate_ci():
t1.delete("1.0",END)
principle=int(principle_field.get())
rate=float(rate_field.get())
time=int(time_field.get())
CI=principle*pow(1+rate/100,time)
t1.insert(END,round(CI-principle,2))

#t1.insert(END,CI)
root=Tk()
root.configure(background='light blue')
root.geometry("400x250")
root.title("Compound Interest Calculator")
label1=Label(root,text="principle amount(Rs):").grid(row=1,column=0)
label2=Label(root,text="rate(%):").grid(row=2,column=0)
label3=Label(root,text="time(years):").grid(row=3,column=0)
label4=Label(root,text="compound interest:").grid(row=5,column=0)
principle_field=Entry(root)
rate_field=Entry(root)
time_field=Entry(root)
t1=Text(root,width=15,height=1)
principle_field.grid(row=1,column=1)
rate_field.grid(row=2,column=1)
time_field.grid(row=3,column=1)
t1.grid(row=5,column=1)
button1=Button(root,text="submit",command=calculate_ci).grid(row=4,column=1,pady=10)
button2=Button(root,text="clear",command=clear_all).grid(row=6,column=1,pady=10)
root.mainloop()
NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

output:

4. Write a GUI program to implement Simple Calculator


NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

from tkinter import*


expression=" "
def press(num):
global expression
expression=expression+str(num)
equation.set(expression)
def equalpress():
try:
global expression
total=str(eval(expression))
equation.set(total)
expression=" "
except:
equation.set("error")
expression=" "
def clear():
global expression
expression=" "
equation.set(" ")
gui=Tk()
gui.configure(background="Light green")
gui.title("simple calculator")
gui.geometry("400x300")
equation=StringVar()
expression_field=Entry(gui,textvariable=equation)
expression_field.grid(columnspan=4,ipadx=70)
button1=Button(gui,text='1',command=lambda:press(1),height=2,width=7)
button1.grid(row=3,column=0)
button2=Button(gui,text='2',command=lambda:press(2),height=2,width=7)
button2.grid(row=3,column=1)
button3=Button(gui,text='3',command=lambda:press(3),height=2,width=7)
button3.grid(row=3,column=2)
button4=Button(gui,text='4',command=lambda:press(4),height=2,width=7)
button4.grid(row=4,column=0)
button5=Button(gui,text='5',command=lambda:press(5),height=2,width=7)
button5.grid(row=4,column=1)
button6=Button(gui,text='6',command=lambda:press(6),height=2,width=7)
button6.grid(row=4,column=2)
button7=Button(gui,text='7',command=lambda:press(7),height=2,width=7)
button7.grid(row=5,column=0)
NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

button8=Button(gui,text='8',command=lambda:press(8),height=2,width=7)
button8.grid(row=5,column=1)
button9=Button(gui,text='9',command=lambda:press(9),height=2,width=7)
button9.grid(row=5,column=2)
button0=Button(gui,text='0',command=lambda:press(0),height=2,width=7)
button0.grid(row=6,column=1)
plus=Button(gui,text='+',command=lambda:press("+"),height=2,width=7)
plus.grid(row=3,column=3)
minus=Button(gui,text='-',command=lambda:press("-"),height=2,width=7)
minus.grid(row=4,column=3)
mul=Button(gui,text='*',command=lambda:press("*"),height=2,width=7)
mul.grid(row=5,column=3)
subt=Button(gui,text='/',command=lambda:press("/"),height=2,width=7)
subt.grid(row=6,column=3)
equal=Button(gui,text='=',command=equalpress,height=2,width=7)
equal.grid(row=6,column=2)
clear=Button(gui,text='c',command=clear,height=2,width=7)
clear.grid(row=6,column=0)
Decimal=Button(gui,text='.',command=lambda:press("."),height=2,width=7)
Decimal.grid(row=7,column=3)
gui.mainloop()

output:
Addition:

Multiplication:
NAME:CHATURSKANDA GANDHI V M CLASS:2BCA,A ROLLNO:CA21434

Division:

You might also like