Practical Programs 24/12/2025
Ex 9
Aim : A program to read from a text file and print the words separated by #
Ex 10
Aim : A program to read from a text file and print the count of vowels, consonants,
lowercase, uppercase characters
Ex 11
Aim : A program to read from a text file and copy all lines starting with ‘t/T’ to another
file
Ex 12
Aim : A program to create and read a binary file
[Link](empno,empname,designation) and search for a particular empno record
import pickle
def create():
try:
with open('[Link]','wb') as f1:
while 1:
a=int(input('Enter empno, 0 to stop'))
if a==0:
break
b=input('Enter empname')
c=input('Enter designation')
L=[a,b,c]
[Link](L,f1)
except:
print('End of creation process')
create()
def display():
try:
with open('[Link]','rb') as f1:
while 1:
x1=[Link](f1)
print('Employee no',x1[0])
print('Employee name',x1[1])
print('Designation',x1[2])
except:
print()
display()
def search(empno):
try:
with open('[Link]','rb') as f1:
f=0
while 1:
x1=[Link](f1)
if x1[0]==empno:
print('Employee no',x1[0])
print('Employee name',x1[1])
print('Designation',x1[2])
f=1
break
except:
if f==0:
print('No record found')
empno=int(input('Enter empno to search'))
search(empno)
Ex 13:
Aim : A program to create a binary file for students(rollno,name,marks) and update
the marks for a particular student whose rollno is given
Ex 14:
Aim: A program to create a CSV file for storing UserID and password and search for the
password for given UserID
import csv
def create():
try:
with open('[Link]','w') as f1:
obj=[Link](f1)
while 1:
a=int(input('Enter user id,0 to stop'))
if a==0:
break
b=input('Enter password')
[Link]([a,b])
except:
print('End of creation')
create()
def search(userid):
try:
with open('[Link]','r') as f1:
obj=[Link](f1)
f=0
for i in obj:
if int(i[0])==userid:
print('Userid:',i[0])
print('Password:',i[1])
f=1
break
if f==0:
print('Record not found')
except:
print('End of search')
userid=int(input('Enter userid'))
search(userid)
27/12/2025
Ex 15:
Aim: A program to implement stack operation
a) Push() to add numbers to the stack
b) Pop() to delete the number
c) Peek() to display the topmost element
d) View() to display all elements
S=[]
def Push():
try:
x=int(input('Enter any number :'))
[Link](x)
except:
print('End of push')
def Pop():
try:
if S==[]:
print('Underflow')
else:
print('Deleted element :',[Link]())
except:
print('End of pop')
def Peek():
try:
if S==[]:
print('Underflow')
else:
print('Topmost element :',S[-1])
except:
print('End of peek')
def View():
try:
if S==[]:
print('Underflow')
else:
for i in range(len(S)-1,-1,-1):
print(S[i],end=' ')
except:
print('End of view')
while 1:
print('\n1 - Push')
print('2 - Pop')
print('3 - Peek')
print('4 - View')
print('5 - Exit')
x=int(input('Enter the choice:'))
if x==1:
Push()
elif x==2:
Pop()
elif x==3:
Peek()
elif x==4:
View()
elif x==5:
break
else:
print('Invalid choice, please try again')
Exercise 17:
1) Create table item(code int primary key,iname varchar(25),qty int,price int,company
varchar(25),tcode char(3));
2) Create table traders(tcode char(3) primary key,tname varchar(25),city varchar(15));
3) Alter table item add foreign key(tcode) reference traders(tcode);
4) Insert into item values(1001,’Digital pad 121’,120,11000,’Xentia’,’T001’);
Insert into item values(....);
5) Insert into traders(‘T01’,’Electronic Sales’,’Mumbai’);
Insert into traders(...);
1) To display the details of all items in the ascending order of name
Select * from item order by iname;
2) To display name,price of all items in the price between 1000 and 2200
Select iname,price from item where price between 1000 and 2200;
3) To display the number of items traded by each trader
Select tcode,count(*) from item group by tcode;
4) To display price, itemname, quantity of all items with quantity is more than 150
Select iname,price,qty from item where qty > 150;
5) To display tradename from delhi or mumbai
Select tname from traders where city in (‘delhi’,’mumbai’);
Question 18:
1) Create table doctor(id int primary key,name varchar(25),dept varchar(15),sex
char(1),exp int);
2) Create table salary(id int primary key,basic int,allow int,cons int);
3) Alter table doctor add foreign key(id) reference salary(id);
4) Insert into doctor values(....);
5) Insert into salary values(....);
1)
Display all doctors who are in dept medicine with more than 10 experience
Select * from doctor where dept=”medicine” and exp > 10;
2) Display average salary (basic+allow) in ent department
Select avg(basic+allow) “Average salary” from doctor natural join salary where dept=”ent”;
3) display minimum allowance of all female doctor
Select min(allow) “Minimum allowance” from doctor natural join salary where sex=”f”;
4) display doctor id, salary (basic + allow)
Select id,basic+allow “Salary” from doctor natural join salary;
5) To display distinct department from table doctor
Select distinct(dept) from doctor;
Exercise 19:
1) To display company name which are having price less than 30000
Select cname from company natural join customer where price <30000;
2) To display company name in reverse alphabetical order
Select cname from company order by cname desc;
3) To increase the price by 1000 for customer name starting with ‘s’
Update customer set price = price +1000 where cname like ‘s%’;
4) To add one more column totalprice of decimal(10,2) to customer table
Alter table customer add totalprice decimal(10,2);
5) To display details of company with product name as mobile
Select * from company where productname =’Mobile’;
Exercise 20:
1) To display details of all teachers in history department
Select * from teacher where department =’history’;
2) To display details of female teachers in math department
Select * from teacher where sex=’f’ and department=’math’;
3) To list the name of teacher with doj in ascending order
Select tname from teacher order by doj;
4) To count number of teacher with age >35 in each department
Select department,count(*) from teacher where age>35 group by department;