Q) WAP to enter product details in the file
product.csv and then from it display those
whose price is more than 250
Program:
import csv
pen ('product.csv', 'w')
n=int (input ("enter limit="))
sv.writer (fo)
w.writerow(['PNo
for i in range(n):
int (input ("enter product no
nput ("enter product name
nt (input ("enter price="))
pn, nm, p)
w.writerow(1)
fo.close()
with open("product.csv",'r', newline="\r\n')as fi:
sv. reader (fi)
for x in r:
if x[2]>'250
print (x)
Output:
enter limit=4
enter product no.=1701
enter product name=soap
enter price=500
enter product no.=1702
enter product name=shampoo
enter price=650
enter product no.=1703
enter product name=face wash
enter price=850
enter product no.=1704
enter product name=scrub
enter price= 175
['PNo', 'Name', 'Price']
{'1701', 'soap', '500"}
['1702', ‘shampoo', '650']
['1703', ‘face wash', '850']
Name', 'Price'])
)Q) WAP to enter the marks of the students
(no. As per user) and then push those names
into the stack whose marks is more than 75
Program:
def push(stk, item) :
stk.append (item)
top=len(stk)-1
s=[]
d={}
n=int (input ("enter the limit="))
for i in range(n):
nm=input ("enter name=")
m=int (input ("enter marks=") )
d['name']=nm
d['marks']=m
if d['marks']>75:
push (s,nm)
print (s)
Output:
enter the limit=4
enter name=aarav
enter marks=74
enter name=riya
enter marks=79
enter name=ravi
enter marks=94
enter name=tina
enter marks=62
[*niya’, *ravi:™]Q) WAP to enter the record for the Student into
the binary file student.dat and then display it
.
Program:
1=[]
import pickle
fo=open ("student.dat', 'wb')
nt (input ("enter limit="))
for i in range(n):
rn=int (input ("enter roll no.="))
nm=input ("enter name=")
m=int (input ("enter mar.
1=[rn,nm,m]
pickle. dump (1, fo)
fo.close()
fi=open("student.dat", 'rb"')
try:
while True:
y=pickle. load (fi)
print (y)
pear found=True Output:
if found==False: saat
print("no record") enter limit=4
fi.close() enter roll no.=1
enter name=aarvi
enter mark=93
Jenter roll no.=2
enter name=bhavna
Jenter mark=75
enter roll no.=3
enter name=daksh
enter mark=88
enter roll no.=4
jenter name=gagan
jenter mark=81
fi, *aanrve", 93]
{2,: *bhavna* , 751
{3, 'daksh', 88]
(4, 'gagan', 81]Q) Display the 5 records from the table
emp using Python interface
Program:
import mysql.connector as MS
t * from emp")
-close()Q) Write a Program to enter the record of
2 students into the table student
Program:
mport mysql.connector as MS
lector .connect (host='localhost',
| con
| co. execute (
|co.execute("insert into
mycon. commit ()
mycon.close()
Output:
(2, ‘Sarthak', 12)
(3, ‘Rayyan’, 11)Q)Display the record of that employee
whose salary is more than 10000 in the
table emp.
Program:
import mysql.connector as MS
mycon=MS.connector.connect (hos calhost',user='root',passord='1234@')
* from emp where salary<{}'. format (10000))
mycon.close()
Output:
sam’, 20000)
(7, ‘naman', 5
(5S,Q) Write a program to create a file
‘poem.txt' and enter lines in it and
then display the last line entered
Program:
fo=open('poem.txt', 'w')
ch='y'
while ch=="y':
s=input ("enter line=")
fo.writelines(s)
ch=input ("enter y for more=")
fo.write('\n"')
fo.close()
fi=open('poem.txt','r')
s=fi.readlines()
print (s[-1])
fi.close()
Output:
enter line=humpty dumpty
enter y for more=y
enter line=sat on the wall
enter y for more=y
enter line=and suddenly fall done
enter y for more=n
and suddenly fall doneQ) Write a program to create a file std.txt
and enter the names of 3 students and
display them in different lines
Program:
| fo=open('std.txt', 'w')
for i in range(0,3):
nm=input ("enter name="
fo.write (nm)
fo.write('\n')
| fo.close ()
fi=open('std.txt','r')
for i in range(0,3):
y=fi.readline()
print (y)
[Steers
Output:
enter name=Isha
enter name=Ravi
enter name=Harsh
Isha
Ravi
Harshimport random
import pickle
def room(a,b, xz, cz, ¢,d,e,£)
fo-open ("data.dat", "ab")
fizopen ("booking. txt", "a")
fiwrite('i')
fi.write('\n')
fi.close()
kop={}
z={1:'Nainital',2:'Chandigarh',3:'Ooty’,4:'Mount Abu’, 5:'Darjeeling',6:'shimla'}
p={ ‘Name’ zb, "Age! :xz, ‘DOB' :cz, 'Address' :c, 'Visit_Date' ze, "Phone’:d}
koptal=p
pickle. dump (kop, fo)
fo.close()
def cancel (s):
fo=open ("data.dat","ab+")
fi-open ("booking. txt", "a+")
fo.seek (0)
fi.seek(0)
sg-fi.readlines ()
pr-len(sg)
fi.close()
c=0
te=1]
for i in range (pr):
set1=pickle. load (fo)
if s in setl.keys():
=ctl
ty=set1.pop(s)
else:
tz.append(set1)
fo.close()
ftropen("data.dat™, "wb")
fn=open ("booking. txt",
for i in range(len(tz)):
pickle. dump (tz[il, ft)
fn.write ("i")
fn.write('\n')
fn.close()
ft.close()
if ¢
return ‘not return’
else:
return ty
fo.close()
def check(m) +
fo-open("data.dat", "ab+")
firopen("booking.txt™,"a+")
fo.seek (0)
fi.seek(0)
eg=fi.readlines ()
pg=len(eg)
fi.close()
c=0for i in range (pg):
set=pickle.load (fo)
if m in set.keys() |
t=set [m]
cac+l
return t
return '\tnot found'
fo.close()
abedefghijklmnopqrstuvwxyZABCDEFGHIJKLMNOPQRSTUVWXYZ"
#2120
if
jb="-"*120
print (a)
print("\t\tTours And Travels")
print (b)
mv='Yes'
while mv=='Yes':
print ("\t\t1.Login")
print ("\t\t2.Exit')
nt (input ("\tEnter your choice="))
if assl:
p=input("\tEnter your full name=")
d=input ("\tEnter your password=")
print ('-'*120)
print ("\t\twelcome',p)
while Tru
print ("\t\t1.Booking")
print (*\t\t2.Cancelation")
print ("\t\t3.Checking")
print (*\t\t4.Logout and Exit')
int (input ("\tEnter your choice="))
if z
print ("\tvisit Booking centre")
qrrandom.randint (7059, 9999)
weinput ("\tEnter your full name=")
nput ("\tenter your age=")
nput ("\tEnter your DOB=")
fro=input ("\tEnter your address='
to=input ("\tEnter your phone no.-")
date=input ("\tenter a visiting date (DD/MM/YYYY) ="
if fro[0] in 1:
print ("\t\t1.Nainital')
print ("\t\t2.Chandigarh")
print ("\t\t3.ooty")
print ("\t\t4.Mount abu")
print (*\t\t5.Darjeeling')
print ("\t\t6.shimla’)
s=int (input ("\tenter your place no. you want to visit="))
w, fz, fx, fro, to, date, 5)
120)
else:
print ("\tcancellation Centre")
int(input("\tenter your visit id-'))
‘ancel (a)
if f=="\tnot found":
tyour booking is successful and your visit id is:",q)print ("\tnot found')
else:
we=f.keys ()
Perec ly<"*I20)
for i in we:
print ("\t\t\t',i,':',f£[i])
print ('-'*120)
print('\t\tCancel success')
print ('-'*120)
elif z
print ('\tChecking centre')
u=int (input ("\tenter your visit id="))
op=check (u)
1=type (op)
if 9 \tnot found':
print('\tnot found")
else:
qw=op. keys ()
print ('\tyour visit id is:',u)
print ('-'*120)
for i in qw:
print ('\t\t\t',i,':',op[il)
print ("-'*120)
elif :
r=input ("enter your password=')
if r==d:
break
else:
print (‘Wrong Password")
print ("-'*120)
my=input ("Do you want to start again(Yes/No)=")
print ("\t\tTHANK YOU")
print ("-'*120)¢:\Users\kjkj\appData\Local\Programs\Python\Python312\tours and travel.¢
Tours And Travels
1.Login
2.Exit
Enter your choic
Enter your full name=SARTHAK PASRICHA
Enter your password=abc@1234
1
Welcome SARTHAK PASRICHA
1. Booking
2.Cancelation
3. Checking
4.Logout and Exit
Enter your choice=1
Visit Booking Centre
Enter your full name=SARTHAK PASRICHA
Enter your age=18
Enter your DOB=08/05/2006
Enter your address=DELHT
Enter your phone no.=9342074734
Enter a visiting date (DD/MM/yy¥yy) =18/02/2025
i.Nainital
2.Chandigarh
3.00ty
4.Mount Abu
S.Darjeeling
6.Shimla
enter your place no. you want to visi
Your booking is successful and your visit id is: 9886
1.Booking
2.Cancelation
3.Checking
4.Logout and Exit
Enter your choice=3
Checking Centre
enter your visit id=9886
your visit id is: 9886
Name : SARTHAK PASRICHA
Age : 18
DOB : 08/05/2006
Address : DELHI
Visit_Date : 18/02/2025
Phone : 93420747341. Booking
2.cancelation
3.Checking
4.Logout and Exit
Enter your choic
Cancellation Centre
enter your visit id-9986
Name : SARTHAK PASRICHA
Age : 18
DOB : 08/05/2006
Address : DELHI
Visit_Date : 18/02/2025
Phone : 9342074734
Cancel success
1. Booking
2.cancelation
3. Checking
4.Logout and Exit
Enter your choice=4
enter your password=abc@1234
Do you want to start again(Yes/No)=no
THANK YOUQ) Write a program to check whether the
string entered is a palindrome or not
Program:
s=input ("enter any string =")
if s[{-1::-1])==s:
int ("string is a pallindrome"™)
RESTART:
enter any string =naman
string is a pallindrome
SSS asssssss==s=s== RESTART:
enter any string =beautiful
string is not a pallindromeQ) Write a user defined function
to check whether the entered year is a
leap year or not
Program:
|def leap (x):
w=x4
return w
s=int (input ("enter year="))
a=leap(s)
if a==0:
print("it is a leap year"
j)else:
print ("it is not a leap year")
Output:
enter year=1988
it is a leap year
= RESTART: C:/Users/kjkj,
enter year=2010
it is not a leap yearQ) Write a Program to enter employee
name , number and salary of an
employee in binary file and display it
Program:
import pickle
def employee s():
d={}
fo=open ("empl.dat", 'wb')
ename=input ("enter employee name=")
eno=int (input ("enter employee number=") )
esal=int (input ("enter salary="))
d['employee name']=ename
d['employee number']=eno
da['salary']=esal
pickle.dump (d, fo)
fo.close()
fi=open("empl.dat", 'rb')
x=pickle.load (fi)
print (x)
fi-.close()
employee_s()
Output:
enter employee name=shrijesh
enter employee number=1765
enter salary=50000
{employee name': '‘shrijesh', ‘employee number’: 1765, ‘salary’: 50000}
|
6Output:
1.push
2.display
entr your choice=1
enetr roll no.=1
enter name=ansh
enter marks=62
enetr roll no.=2
enter name=arsh
enter marks=85
enetr roll no.=3
enter name=ashi
enter marks=79
enetr roll no.=4
enter name=faaz
enter marks=59
enetr roll no.=5
enter name=geeta
enter marks=71
1.push
2.display
entr your choice=2
({'roll no.', 'name', 'marks']
{[5, "geeta', 71]
[4, *faaz", 39]
(3, ‘ashi', 79]
(a; tages, 65)
(1, 'ansh', 62]
1.push
2.display
entr your choice=3
wrong choiceQ) Write a program with the help of stack
to add record of 5 students and display it
Program:
def push(stk, item) :
stk. append (item)
top=len(stk)-1
def display(stk):
if stk==[]:
print ("stack is empty")
else:
top=len (stk)-1
print (stk[top])
for i in range(top-1,-1,-1):
print (stk[i])
s=[]
top=None
while True:
print ("1.push")
print ("2.display")
ch=int (input ("entr your choice="))
if ch==1:
1=[]
for i in range(0,5):
rn=int (input ("enetr roll no.="))
nm=input ("enter name=")
m=int|(input ("enter marks="))
1=[rn,nm,m]
push (s,1)
push(s, ['roll no.', 'name', 'marks'])
elif ch==2:
display (s)
else:
print ("wrong choice") 4
breakOutput:
enter roll no.=1
enter name=ansh
enter marks=72
enter roll no.=2
enter name=arsh
enter marks=89
enter roll no.=3
enter name=deepak
enter marks=84
ise ne. ‘name’, ‘marks: |
[]
at Sema gs set!
[]
2 an BS
[]
['3', 'deepak', '84']
(]Q) Write a program to create csv file
student.csv to store student data roll no.
name and marks. Obtain data from user
and store it into your file
Program:
import csv
fo=open("student.csv", "w")
| st=csv.writer (fo)
|st.writerow(['roll no.', 'name', 'marks'])
for i in range(0,3):
rn=int (input ("enter roll no.="))
nm=input ("enter name=")
m=int (input ("enter marks="))
1=[rn,nm,m]
st.writerow (1)
fo.close()
fi=open ("student.csv", "r")
x=csv. reader (fi)
for an =:
print (i)
fi.close()Q) Write a program to create a dictionary
containing names of position holders as
key and their position as values
Program:
p_holders={}
n=int (input ("enter the no. of
Soe a. range (0,n):
put ("enter nameof student=")
po=int (input ("enter position ="))
p_holders [nm]=po
poition holders=") )
print ("required dictionary=",p_holders)
Output:
enter the no.
of poition holders=4
enter positi|
required dictionary= {'AJAY': 1, 'RAGHAV': 2, ‘SUMIT': 3
, “TEENA': 4)
1Q) Write a user defined function
count() to enter two strings and check
whether their lengths are equal or not
Program:
def count (x,y):
si=len (x)
s2=len(y)
if sl==s2:
return "both length are equal"
else:
return "both length are unequal"
a=input ("enter first string=")
b=input ("enter second string=")
c=count (a,b)
print (c)
Output:
enter first string=hello
enter second string=world
both length are equal
= RESTART: C:/Users/kjkj/AppData
enter first string=myself
enter second string=student
both length are unequal