Computer Practical
Computer Practical
2024-2025
NAME:- KARTIK
CLASS:- XII-A
School:-The Millennium School,
Ayodhya Road, Barabanki.
INDEX
Sl.no Program
Question1 Write a menu driven program to perform mathematical calculations like
Addition, Subtraction, Division, Multiplication between two integers. The
program should continue running until user gives the choice to quit.
Write a program which takes the number of people of various age groups
as input and prints a ticket. At the end of the journey, the program states
the number of passengers of different age groups who travelled and the
total amount received as collection of fares.
Question5 Write a program that defines a function ModifyList(L) which receives a list
of integers , updates all those elements which have 5 as the last digit with
1 and rest by 0.
Question6 Write a program that defines a function MinMax(T) which receives a tuple
of integers and returns the maximum and minimum value stored in tuple.
Question10 Write a program to create a menu driven program using user defined
functions to manage details of Applicants in a binary file APPLICANTS.DAT .
Applicant details include(AppID,AName,Qualification) The available choices
are:
1-Create File
2-Add Applicant
3-Search Applicant on the basis of AppID
4-Modify Applicant
5-Quit
Question11 Write a program to create a menu driven program using user defined
functions to manage Telephone contacts of your friends in a CSV file
MyFriend.csv. (Contact details includes Name,Telephone Contact
No.,EmailID,Address)The available choices are:
1-Create File
2-Add Friend
3-Search Friend
4-Quit
Question12 Write definition of a user defined function PUSHNV(N) which
receives a list of strings in the parameter N and pushes all strings
which have no vowels present in it , into a list named NoVowel.
Write a program to input 10 words and push them on to a list ALL.
Question15 Sql query for inserting values in the table named club
Question16 Write sql staementd for the following based in the table club.
Question17 . Create following tables in database MYORG with appropriate
data type using SQL commands of following structure.
Table : Company Table Customer
CID Primary key CustId Primary Key
Name Not Null Name Not Null
City Not Null Price Not Null
Product Name Not Null Qty Check greater
than 0
CID Foreign Key
Question18 Write SQL commands to insert following data in above created
tables Company and Customer , also list all data .
Question19 Write sql commands for the following queries based on tables
company and customer
Question20 Write a pythom interface program using mysql to insert rows in
table club in database games
Question21 Write Python interface program using MySQL to increase price
by 10% in table CUSTOMER of MYORG database
Question22 Write a Python interface program using MySQL to delete all those
customers whose name contains Kumar from table CUSTOMER in
database MYORG.
CERTIFICATE
…………………… ……………………
INTERNAL EXAMINER EXTERNAL EXAMINER
HARDWARE AND SOFTWARE
DETAILS
PC SPECS
CORE I3 10400F
GT 610 GPU
4 GB RAM
SOFTWARE
WINDOWS 10
PYTHON 3.9
PYTHON IDLE
PROGRAM NO. 1 :
SOURCE CODE :
main()
########### output #############
'''enter the value for x5
enter the no of terms4
the sum of the series is 781.0'''
OUTPUT:
PROGRAM N0.3
SOURCE CODE:
for i in range(1,n+1):
print(' '*(n-i),end="")
print('*'*c)
c=c+2
OUTPUT :
PROGRAM NO. 4:
SOURCE CODE:
adults = int(input("Enter the number of adults (age 18 and above): "))
children = int(input("Enter the number of children (age 5 to 17): "))
kids = int(input("Enter the number of kids (age below 5): "))
print("TICKET DETAILS:")
print("Adults (age 18 and above):",adults)
print("Children (age 5 to 17):",children)
print("Kids (age below 5):",kids)
print("Total Fare Collected:",(adults*50)+(children*20)+(kids*0))
OUTPUT:
PROGRAM NO. 5:
SOURCE CODE :
def ModifyList(L):
for i in range(len(L)):
if L[i] % 10 == 5:
L[i] = 1
else:
L[i] = 0
return L
# Sample RUN:
modified_list = ModifyList(my_list)
print(modified_list)
OUTPUT:
PROGRAM NO. 6:
SOURCE CODE:
def minmax(t): # Method to compute minimum and maximum value
min=max=t[0]
for i in range(1,len(t)):
if t[i]>max:
max=t[i]
if t[i]<min:
min=t[i]
return min,max
############## Main #################
L=[]
print(" Enter the elements for Tuple")
for i in range(5):
x=int(input("enter the value"))
L.append(x)
t=tuple(L)
print("Elements of tuple are",t)
OUTPUT :
PROGRAM NO. 7:
SOURCE CODE:
def INDEX_LIST(L):
indexlist = []
for i in range(len(L)):
if L[i] != 0:
indexlist.append(i)
return indexlist
OUTPUT :
PROGRAM NO. 8:
SOURCE CODE:
def createfile(): # adding lines to file
infile=open("poem.txt","a")
ch='y'
while ch=='y' or ch=='Y':
s=input("enter line")
infile.write(s+"\n")
ch=input("do you wish to continue")
print("Lines successfully added in file")
infile.close() #closing file
print(sum ,"\t",a)
def longline():
infile=open("poem.txt","r")
s=infile.readlines()
infile.close()
max=" "
for i in s:
if(len(i)>len(max)):
max=i
print("the line with max length is")
print(max)
ch="Y"
while ch=='y' or ch=='Y':
print("1. Create stry.txt file\n\
2. Print freqency table of words\n\
3.Print longest line")
choice=int(input("enter your choice"))
if choice==1:
createfile()
elif choice==2:
generatefreq()
elif choice==3:
longline()
else:
print("invlid choice")
ch=input("do you wish to continue")
OUTPUT :
PROGRAM NO. 9:
SOURCE CODE:
def removalofa(fname):
with open(fname, 'r') as f:
lines = f.readlines()
with open('destination_file.txt', 'w') as d:
for i in lines:
if 'a' not in i:
d.write(i)
def beforeremoval():
infile=open("poem.txt","r")
s=infile.read()
infile.close()
print("Original contents Bedore removal")
print(s)
def afterremoval():
infile=open("poem2.txt","r")
s=infile.read()
infile.close()
print("New file after removal of letter a")
print(s)
# Calling Methods
beforeremoval()
fname="poem.txt"
removalofa(fname)
afterremoval()
OUTPUT :
PROGRAM NO. 10:
SOURCE CODE:
import pickle
def create():
f=open('Applicants.dat','wb')
f.close()
def add():
f=open('Applicants.dat','ab')
AppId=input('Enter Id of applicant')
AName=input('Enter applicant name')
Qualification=input('Enter qualification of applicant')
x=[AppId,AName,Qualification]
pickle.dump(x,f)
f.close()
def display():
f=open('Applicants.dat','rb')
try:
while True:
y=pickle.load(f)
print(y)
except EOFError:
f.close()
def search():
f=open('Applicants.dat','rb')
search=input('Enter qualifications you want to search')
c=0
try:
while True:
y=pickle.load(f)
if y[2].lower()==search.lower():
print(y)
c+=1
except EOFError:
if c==0:
print('No application of the searched qualfication present')
f.close()
def modify():
f=open('Applicants.dat','rb+')
c=int(input('What you want to modify? 1-Applicant name 2-Applicant qualification'))
Id=input('Enter applicant id whose details is to be modified')
try:
while True:
x=f.tell()
y=pickle.load(f)
if y[0]==Id:
if c==1:
name=input('Enter new name')
y[1]=name
f.seek(x)
pickle.dump(y,f)
f.close()
break
elif c==2:
qualify=input('Enter new qualification')
y[2]=qualify
f.seek(x)
pickle.dump(y,f)
f.close()
break
else:
print('Choose correct option')
f.close()
break
except EOFError:
print('Applicant id not found')
f.close()
while True:
print('''Choices are
1-Create file 2-Add applicant3-Display4-Search on basis of qualificatioon5-
Modify6Quit''')
ch=int(input('Enter a choice'))
if ch==1:
create()
elif ch==2:
add()
elif ch==3:
display()
elif ch==4:
search()
elif ch==5:
modify()
elif ch==6:
print('Program Terminated')
break
else:
print('Input correct choice')
OUTPUT :
PROGRAM NO. 11:
SOURCE CODE:
import csv
def create() :
f=open("MyFriend.csv","w")
print("CSV FILE CREATED SUCCESFULLY")
def add():
f=open(" MyFriend.csv","w")
wobj=csv.writer(f)
n=int(input("how many data is to be added"))
for i in range(n):
name=input("enter your friends name")
fco=int(input("enter contact no."))
fem=input("enter email")
fad=input("enter the address")
l=[name, fco, fem,fad]
wobj.writerow(l)
ch=input("do you want o to add more data")
if ch.lower=="n":
break
def search():
f=open("MyFriend.csv","r")
robj=csv.reader(f)
for i in robj:
fphno=int(input("enter phone number to be searched"))
if fphno in i:
print (i)
else:
print ("record not found")
def display():
f=open(" MyFriend.csv","r")
robj=csv.reader(f)
for i in robj:
print(i)
while True:
print ("1-to create file \n2-to add friend \n3-to search friend \n4-display
\n5-quit")
ch=int(input("enter choice"))
if ch==1:
create()
elif ch==2:
add()
elif ch==3:
search()
elif ch==4:
display()
else:
break
OUTPUT :
PROGRAM NO.12:
SOURCE CODE:
NoVowel=[]
def pushnv(n):
for word in n:
flag=0
for j in word:
if j in "AEIOUaeiou":
flag=1
break
if flag==0:
NoVowel.append(word)
def pop():
for i in range(len(NoVowel)):
print("Deleted elemnet is",NoVowel.pop())
else:
print("stack is empty")
## Main Program
def push(sitem):
global count
for i in sitem.keys():
if sitem[i]>75:
stk.append(i)
count=count+1
sitem={}
for i in range(5):
try:
sitem[input("enter the stationary name")]=int(input("enter the price"))
except:
print("error occured")
push(sitem)
print("elements pushed with the price >75",count)
PROGRAM NO.14:
SOURCE CODE:
Create table club(CoachId int primary key,CoachName varchar(50) not null,Age
int not null,Sports char(30),DateofApp date,Pay int,Sex char(1));
PROGRAM NO.15:
SOURCE CODE:
insert into club values(1,'Kukreja',35,'Karate','1996/03/27',10000,'M');
insert into club values(2,'Ravina',34,'Karate','1998-01-20',12000,'F');
insert into club values(3,'Karan',32,'Squash','2000-02-19',20000,'M');
insert into club values(4,'Tarun',33,'Basket Ball','2005-01-01',15000,'M');
insert into club values(5,'Zubin',36,'Swimming','1998-02-24',7500,'M');
insert into club values(6,'Ketaki',33,'Swimming','2001-12-23',8000,'F');
Select * from club;
PROGRAM NO.16:
i)List all coaches whose sports is swimming or karate.
select * from club where sports="swimming" or sports=’Karate’;
create Table Customer(Sustid int primary key,Name varchar(40) Not Null,price int Not
Null,Qty int Check(qty>0),CID int references company(cid));
PROGRAM NO.18:
SOURCE CODE:
insert into company values(111,'Sony','Delhi','TV');
insert into company values(222,'Nokia','Mumbai','Mobile');
insert into company values(333,'Onida','Delhi','TV');
insert into company values(444,'Blackberry','Mumbai','Mobile');
insert into company values(555,'Samsung','Chennai','Mobile');
insert into company values(666,'Dell','Delhi','Laptop');
insert into customer values(101,'Rohan Sharma',70000,20,222);
insert into customer values(102,'Deepak Kumar',50000,10,666);
insert into customer values(103,'Mohan Kumar',30000,5,111);
insert into customer values(104,'Sahil Bansal',35000,3,333);
insert into customer values(105,'Neha Soni',25000,7,444);
insert into customer values(106,'Sonal Agarwal',20000,5,333);
insert into customer values(107,'Arjun Singh',50000,15,666);
PROGRAM NO.19:.
1) Display those company names having price less than 30000.
select c.name from company c ,customer c1 where c.cid=c1.cid and
c1.price>30000;
2) To increase price by 1000 for those customers whose name starts with
‘S’.
update customer set price=price+1000 where name like 's%';
con=sq.connect(host="localhost",user="root",database="GAMES",passwd="lpc@1
23")
if con.is_connected():
cr=con.cursor()
choice='Y'
while choice=="Y":
print("record inserted")
choice=input("do you wish to continueY/N").upper()
else:
print("connection could not be established")
con.close()
PROGRAM NO.21:
SOURCE CODE:
import mysql.connector as sq
con=sq.connect(host="localhost",user="root",password="lpc@123",database="MY
ORG”)
if con.is_connected():
cr=con.cursor()
choice='Y'
cr.execute("UPDATE CUSTOMER SET PRICE=PRICE+PRICE*.10")
print("recordS UPDATED")
else:
print("connection could not be established")
con.close()
PROGRAM NO.22:
SOURCE CODE:
import mysql.connector as sq
con=sq.connect(host="localhost",user="root",password="lpc@123",database="MY
ORG")
if con.is_connected():
cr=con.cursor()
choice='Y'
cr.execute("DELETE FROM CUSTOMER WHERE NAME LIKE
‘%KUMAR%’ ”)
print("recordS UPDATED")
else:
print("connection could not be established")
con.close()