NAGENDRA ACHARI II BCA C CA24165
2. Write a menu driven program to create bank account class. Class should
support following methods 1. Deposite 2. Withdraw 3. Get balance create a
sub class saving account class that behaves just like a Bank account but
also has an interest rate and method that increases the balance by the
appropriate amount of interest
class bankaccount:
def __init__(self, name, actno, balance):
[Link]=name
[Link]=act no
[Link]=balance
def deposit(self, amount):
[Link]=[Link]+amount
def withdraw(self,amount):
if [Link] < amount:
print("insufficient balance")
else:
[Link]=[Link]-amount
print(f"Withdrawn successfully {amount}. New balance is
{[Link]}.")
def get_balance(self):
return [Link]
def cus_disp(self):
print(f"Customer Name: {[Link]}")
print(f"Account Number: {[Link]}")
print(f"Balance: {[Link]}")
class savingsaccount(bankaccount):
def add_interest(self):
self.r=float(input("Enter rate of interest: "))
interest = [Link]*self.r
[Link]=[Link]+interest
print(f"Interest added. New balance is {[Link]}.")
n = input("Enter customer name: ")
a = int(input("Enter account number: "))
b = int(input("Enter initial balance: "))
account = savingsaccount(n,a,b)
while True:
print("\n bank account menu")
print("1. Deposit")
print("2. Withdraw")
print("3. get Balance")
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
print("4. add interest ")
print("5. display ")
print("6. quit")
choice = int(input("Enter your choice (1 to 6): "))
if choice == 1:
amount1 = float(input("Enter amount to deposit: "))
[Link](amount1)
elif choice == 2:
amount = float(input("Enter amount to withdraw: "))
[Link](amount)
elif choice == 3:
print(f"Current balance is {account.get_balance()}.")
elif choice == 4:
account.add_interest()
elif choice == 5:
account.cus_disp()
elif choice == 6:
print("Exiting the program.")
break
else:
print("Invalid choice. Please try again.")
OUTPUT
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
1 Program to create a class employee with empno,name,depname,
designation, age and salary and perform the following function
i) Accept details of employee
ii) search given employee using empno
iii) display employee details in neat format
class emp:
def __init__(self):
[Link]=None
[Link]=None
[Link]=None
[Link]=None
[Link]=None
[Link]=None
def getemp(self):
[Link]=(int(input("Enter ID :")))
[Link]=(input("Enter Name :"))
[Link]=(input("Enter DEPARTMENT :"))
[Link]=(input("Enter DESIGNATION :"))
[Link]=(int(input("Enter AGE :")))
[Link]=(int(input("Enter SALARY :")))
def disemp(self):
print("__"*30)
print(f"Employee Number:{[Link]}")
print(f"Employeen Name:{[Link]}")
print(f"Employeen Age:{[Link]}")
print(f"Employeen Department:{[Link]}")
print(f"Employeen Designation:{[Link]}")
print(f"Employeen Salary:{[Link]}")
print("__"*15)
def search(self,empno):
if empno==[Link]:
return 1
else:
return 0
n=int (input("Enter Total Number of Employees"))
L=[]
for i in range(n):
E=emp()
[Link]()
[Link](E)
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
for item in L:
[Link]()
empid=int (input("Enter employee id to search:"))
found =0
for el in L:
found=[Link](empid)
if(found==1):
print("Employee found")
[Link]()
if(found==0):
print("Employee not found")
OUTPUT
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
8. Write a pandas program to join the 2 given data frames along rows
sample data frames may contain details of student like roll no, name, total
marks
import pandas as pd
stud1 = [Link]({
'Roll No.': ['S101', 'S102', 'S103', 'S104', 'S105'],
'Name':['Rama', 'Naga', 'Puni', 'Sachin', 'Muku'],
'Marks': [200,210,190,222,119]},
index = [1,2,3,4,5])
stud2 = [Link]({
'Roll No.': ['S104', 'S105', 'S106', 'S107', 'S108'],
'Name':['Ramesh', 'Hemu', 'Dilip', 'Shree', 'Manju'],
'Marks': [201,200,198,219,201]},
index = [6,7,8,9,10])
print("Original DataFrames")
print(stud1)
print("--------------------------------")
print(stud2)
print("\n Join the said two dataframes along rows")
result_data = [Link]([stud1,stud2])
print(result_data)
OUTPUT
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
5. Create a table student table(regno, name and marks in 3 subjects) using
my SQL and perform
a. to accept the details of students and store in database
b. to display the details of all the students
c. delete particular student record using regno
import sqlite3
con=[Link]('[Link]')
cl=[Link]()
[Link]('''create table if not exists student
(regno int primary key,
name text not null,
sub1 int not null,
sub2 int not null,
sub3 int not null)''')
print("student table created successfully")
def insert_student():
try:
regno=int(input("enter registration number:"))
name=input("Enter name:")
sub1=int(input("Enter marks for subject1:"))
sub2=int(input("Enter marks for subject2:"))
sub3=int(input("Enter marks for subject3:"))
if(sub1>100 or sub2>100 or sub3>100):
raise ValueError
[Link]('''insert into student values(?,?,?,?,?)''',
(regno,name,sub1,sub2,sub3))
print("Student record created successfully")
[Link]()
except sqlite3:
print("Please put unique registration number ")
except ValueError:
print("Please enter correct valid data")
def display_student():
[Link]('''select * from student''')
record=[Link]()
if record==[]:
print("No records found")
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
else:
print("(Regno: Name: Sub1: Sub2: Sub3: )")
for row in record:
print(row)
def delete_stduent():
r=int(input("Enter registration number to delete"))
[Link](f'''select *from student where regno={r}''')
row=[Link]()
if row is None:
print("No student found with that registration number")
else:
[Link](f'''delete from student where regno={r}''')
[Link]()
print("student deleted successfully")
while True:
print("1. Insetrt studnt record")
print("2. Display all studnt record")
print("3. Delete a studnt record")
print("4. Exit")
ch=int(input("Enter your choice"))
if ch==1:
insert_student()
elif ch==2:
display_student()
elif ch==3:
delete_stduent()
elif ch==4:
break
else:
print("Invalid choice")
[Link]()
[Link]()
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
OUTPUT
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
4. Write a GUI program to implement simple calculation
from tkinter import *
expression=""
class mycalci:
def __init__ (self,root):
self.f=Frame(root,width=400,height=250)
[Link](0)
[Link]()
[Link]=StringVar()
self.button_layout=[
("7",1,0),("8",1,1),("9",1,2),("/",1,3),
("4",2,0),("5",2,1),("6",2,2),("*",2,3),
("1",3,0),("2",3,1),("3",3,2),("-",3,3),
("0",4,0),(".",4,1),("=",4,2),("+",4,3)]
for(t1,row,col)in self.button_layout:
button=Button(self.f,text=t1,padx=20,pady=20,font=("Arial",18),command=la
mbda f1=t1:[Link](f1) if f1!="=" else [Link]())
[Link](row=row,column=col)
self.ans_field=Entry(self.f,textvariable=[Link])
self.ans_field.grid(row=0,column=0,columnspan=4,ipadx=70,ipady=20)
self.clear_button=Button(self.f,text="c",padx=20,pady=20,font=("Erial",18),co
mmand=[Link])
self.clear_button.grid(row=5,column=1)
def press(self,num):
global expression
expression=expression+str(num)
[Link](expression)
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
def equalpress(self):
try:
global expression
total=str(eval (expression))
[Link](expression+'='+(total))
expression=""
except:
[Link]("ERROR")
expression=""
def clear(self):
global expression
expression=""
[Link]("")
root=Tk()
[Link]("Calculator")
t=mycalci(root)
[Link]()
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
6. Create a table employee (empno ,name and salary)using sqlite and
perform the followings
a. To accept the details of a employee and store it in database
b. To display the details of a specific employee
c. To display employee details whose salary list within a certain range
import sqlite3
con = [Link]('[Link]')
c1 = [Link]()
[Link](''' Create table if not exists Employee(empno int PRIMARY KEY,
name text NOT NULL,
sal real NOT NULL)''')
print("employee table created successfully")
def insert_emp():
try:
e= int(input("enter the employee number: "))
n = input("enter the employee name: ")
s = int(input("enter the employee salary: "))
[Link]('''insert into Employee values(?,?,?)''',(e,n,s))
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
print("employee record created successfully")
[Link]()
except [Link]:
print("please put correct unique empno number")
except ValueError:
print("please enter correct valid data")
def display_all():
[Link]('''select * from Employee''')
record = [Link]()
if record == []:
print("no records found")
else:
print("(empno: name: sal: )")
for row in record:
print(row)
def display_emp():
eno = int(input("enter the employee number to display: "))
[Link](f'''select * from Employee where empno={eno}''')
record = [Link]()
if record is None:
print("no employee found with this empno")
else:
print("(empno: name: sal: )")
print(record)
def sal_emp():
r1 = int(input("enter the starting salary range:"))
r2 = int(input("enter the ending salary range:"))
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
[Link](f'''select * from Employee where sal between {r1} and {r2}''')
record = [Link]()
if record == []:
print("no employee found in this salary range")
else:
print("(empno: name: sal: )")
for row in record:
print(row)
while True:
print("1. Insert Employee Record")
print("2. Display All Employee Records")
print("3. Display Employee Record by Empno")
print("4. Display Employees in Salary Range")
print("5. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
insert_emp()
elif choice == 2:
display_all()
elif choice == 3:
display_emp()
elif choice == 4:
sal_emp()
elif choice == 5:
break
else:
print("Invalid choice, please try again.")
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
[Link]()
[Link]()
OUTPUT
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
7. Program using user defined exception class that will ask the user to
enter a no. until he guesses a stored no. correctly to help them figure it out
a hint is provided whether their guess is greater than or less than the stored
number using user defined exception.
import random
class lower(Exception):
pass
class high(Exception):
pass
class correct(Exception):
pass
def check(num):
while True:
try:
g=int(input(“Guess a number:”))
if g<num:
raise lower
elif g>num:
raise high
else:
raise correct
except lower:
print(“Too low, Try again”)
except high:
print(“Too Higher, Try again”)
except correct:
print(“Congratulations”)
break
num=[Link](50)
check(num)
OUTPUT
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
2. Program using user defined function to find area of rectangle, square,
circle, and triangle by accepting suitable input parameter from user
def rect():
length=int(input("Enter length"))
breadth=int(input("Enter breadth"))
rectarea=length*breadth
print(f"Area of rectangle is {rectarea}")
def square():
a=int(input("Enter area"))
area=a*a
print(f"Area of square is {area}")
def tri():
base=int(input("Enter base"))
height=int(input("Enter height"))
triarea=0.5*base*height
print(f"Area of triangle is {triarea}")
def circ():
radius=int(input("Enter radius"))
cir=3.14*(radius*radius)
print(f"Area of square is {cir}")
while True:
print("Choose your option")
print("1. area of rectangle")
print("2. area of square")
print("3. area of triangle")
print("4. area of circle")
print("5. exit")
i=int(input("Enter your choice"))
if i==1:
rect()
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
elif i==2:
square()
elif i==3:
tri()
elif i==4:
circ()
elif i==5:
break
else:
print("Invalid option")
OUTPUT
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
3. Create a GUI to input principal amount,rate of interest and number of
year,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 *
class MyButton:
def __init__(self,root):
self.f=Frame(root,width=400,height=250,bg="cyan")
[Link](0)
[Link]()
self.label1=Label(self.f,text="principal Amount(rs):",fg='black',bg='red')
self.label2=Label(self.f,text="Rate(%):",fg='black',bg='red')
self.label3=Label(self.f,text="Time(years):",fg='black',bg='red')
self.label4=Label(self.f,text="Coumpound Interest:",fg='black',bg='red')
[Link](row=1,column=0,padx=10,pady=10)
[Link](row=2,column=0,padx=10,pady=10)
[Link](row=3,column=0,padx=10,pady=10)
[Link](row=5,column=0,padx=10,pady=10)
self.principal_field=Entry(self.f)
self.rate_field=Entry(self.f)
self.time_field=Entry(self.f)
self.compound_field=Entry(self.f)
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
self.principal_field.grid(row=1,column=1,padx=10,pady=10)
self.rate_field.grid(row=2,column=1,padx=10,pady=10)
self.time_field.grid(row=3,column=1,padx=10,pady=10)
self.compound_field.grid(row=5,column=1,padx=10,pady=10)
self.button1=Button(self.f,text="Submit",bg="red",fg="black",command=self.c
alculate_ci)
self.button2=Button(self.f,text="clear",bg="red",fg="black",command=[Link]
r_all)
[Link](row=4,column=1,padx=10,pady=10)
[Link](row=6,column=1,padx=10,pady=10)
def clear_all(self):
self.principal_field.delete(0,END)
self.rate_field.delete(0,END)
self.time_field.delete(0,END)
self.compound_field.delete(0,END)
self.principal_field.focus_set()
def calculate_ci(self):
[Link]=int(self.principal_field.get())
[Link]=float(self.rate_field.get())
[Link]=int(self.time_field.get())
[Link]=[Link]*(pow((1+[Link]/100),[Link]))
self.compound_field.insert(10,round([Link],2))
root=Tk()
[Link]("Compound Interest")
mb=MyButton(root)
[Link]()
OUTPUT
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
1. write a program create a list with N element find all unique elements
in the list if an element is found only once in the list then add that
element to the unique list
num=[]
ulist=[]
n=int(input("enter the number of elements to be inserted:\n"))
for i in range(n):
ele=input("enter the elements:")
[Link](ele)
print("the elements in the list are:")
print(num)
for e in num:
if([Link](e)==1):
[Link](e)
print("The unique elements in list are :")
print(ulist)
OUTPUT
OUTPUT 2
ALVAS COLLEGE MOODUBIDIRE PAGE NO:
NAGENDRA ACHARI II BCA C CA24165
ALVAS COLLEGE MOODUBIDIRE PAGE NO: