12pracperformance24-25_Python
12pracperformance24-25_Python
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
max(salary)
7
65000