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

12pracperformance24-25_Python

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

12pracperformance24-25_Python

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Programs for performance for pre-board practical exam 2024-25 Class XII

Note: a)Students have to solve 1 python program from Q1 to Q4 from Group A


as per allotted slip.
b)Students have to solve 1 sql program from Q1 to Q4 from Group B as per
allotted slip.
1. Remove all lines that contain character ‘a’ in a file and write it to another
file.
f1=open("file1.txt",'w')
m='''apple
mango
cherry
chikoo'''
f1.write(m)
f1.close()
f1=open("file1.txt",'r')
x=f1.readlines()
print("orignal file is",x)
f1.close()
f1=open("file1.txt",'w')
f2=open("file2.txt",'w')
for i in x:
if 'a' in i or 'A' in i:
f2.write(i)
else:
f1.write(i)
f1.close()
f2.close()
f1=open("file1.txt",'r')
y=f1.readlines()
print("after removing lines containing a in file1",y)
f1.close()
f2=open("file2.txt",'r')
z=f2.readlines()
print("after adding lines containing a in file2",z)
f2.close()

1
2. Create binary file having name, roll, marks. Search a given name and
display it. If it is not found display appropriate message
import pickle
def write():
list =[]
whileTrue:
roll = input("Enter student Roll No:")
sname = input("Enter student Name :")
marks=int(input('enter marks'))
student =[roll,sname,marks]
list.append(student)
choice= input("Want to add more record(y/n) :")
if(choice=='n'):
break
file = open("studentmarks.dat","wb")
pickle.dump(list,file)
print("record is
updated") file.close()
def read():
file = open("studentmarks.dat", "rb")
list = pickle.load(file)
for i in list:
print(i)
file.close()
def search():
file = open("studentmarks.dat", "rb")
list = pickle.load(file)
found = 0
roll =input('Enter roll no that you want to search in binary file :')
for r in list:
if r[0]==roll:
print("record is found name is ",r[1])
found=1
break
if found==0:
print("record is not
found") file.close()
print("menu")

2
print("1.create record")
print("2.display record")
print("3.search record")
while True:
m=input("do you want to continue y/n")
if m=='y':
ch=input('choice')
if ch=='1':
write()
if ch=='2':
read()
if ch=='3':
search()
else:
print("you pressed no")
break

3
3. Write a Python program to implement a stack using list. Enter numbers
to be added or removed from list using functions push() and pop().
stack=[]
n=3
def push():
if len(stack)==n:
print("stack overflow")
else:
value=int(input("enter element in stack"))
stack.append(value)
print(stack)
def pop():
if len(stack)==0:
print("stack underflow")
else:
x=stack.pop()
print(x,"is removed from stack")
print(stack)
while True:
print('''
1. Push value in stack
2.Pop value from stack
3.Exit''')
choice=int(input("enter choice"))
if choice==1:
push()

elif choice==2:
pop()
else:
Break

4
5
4. User registration and login using CSV file in python
import csv
def writecsv(username,password):
f=open("user.csv",'a')
writer=csv.writer(f)
writer.writerow([username,password])
f.close()
def readcsv():
username=input("enter username")
password=input("enter password")
with open("user.csv",'r') as f:
reader=csv.reader(f)
for row in reader:
if row==[username,password]:
print(row)
print("you are logged
in") break
else:
print("you have to register first")
f.close()
writecsv("vijay","ab@11")
writecsv("priya","cd@22")
writecsv("ramesh","ef@33")
readcsv()

6
Group B SQL
create database emp;
use emp;
create table employee(eid int, ename char(20), salary float);
show tables;
describe employee;
insert into employee values(101,'priti',50000.0);
insert into employee values(102,'vikas',55000.0);
insert into employee values(103,'ram',60000.0);
insert into employee values(104,'shyam',65000.0);
insert into employee values(105,'swati',45000.0);
select * from employee;
Tables_in_mycompiler
employee
Field Type Null Key Default Extra
eid int YES NULL
ename char(20) YES NULL
salary float YES NULL
eid ename salary
101 priti 50000
102 vikas 55000
103 ram 60000
104 shyam 65000
105 swati 45000

Select * from employee where eid=103;

eid ename salary


103 ram 60000

select * from employee where ename like 's%';

eid ename salary


104 shyam 65000
105 swati 45000

select max(salary) from employee;

max(salary)

7
65000

insert into employee values(106,'vijay',53000.0);

eid ename salary


106 vijay 53000

select count(*) from employee where salary>55000;


count(*)
2

update employee set salary=52000 where ename='priti';


eid ename salary
101 priti 52000

select * from employee order by salary;


eid ename salary
105 swati 45000
101 priti 52000
106 vijay 53000
102 vikas 55000
103 ram 60000
104 shyam 65000

delete from employee where ename='shyam';


eid ename salary
101 priti 52000
102 vikas 55000
103 ram 60000
105 swati 45000
106 vijay 53000

You might also like