Professional Documents
Culture Documents
Session 2023
2023-2024
GSBV,BURARI 1 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
taBle oF ContentS
S.NO DESCRIPTION Page No. Remark
S.no
PYTHON PROGRAMS
1. WAP in Python to Find the Factorial of a number using function. 4-5
3. Write a program in Python to input the value of x and n and print the sum of the following series 6
S.no DESCRIPTION Page No. Remark
4. WAP in python to read a text file and print the number of vowels and consonants in the file 7
5. WAP in Python to read a text file and print the line or paragraph starting with the letter ‘S’ 7-8
6. WAP in Python to read a text file and print the number of uppercase and lowercase letters in 8-9
The file
7. WAP in Python to create a binary file with name and roll number of the students. Search for 10-11
a given roll number and display the name of student
8. Create a binary file with roll_no, name and marks of some students and update the marks of 11-13
specific student.
9. Create a binary file with eid, ename and salary and update the salary of the employee 13-15
10. Create a text file and remove the lines from the file which contains letter ‘K’ 16-17
11. Create a binary file with 10 random numbers from 1 to 40 and print those numbers. 18
12. Write a program in Python to create a CSV file with the details of 5 students. 19-20
13. WAP in Python to read a CSV file. 20-21
14. Write a menu driven program which insert, delete and display the details of an employee such 21-23
as eid, ename and salary using Stack
15. Write a menu driven program which insert, delete and display the details of a book such as 23-26
book_id, book_name and price using Stack
16. Write a menu driven program which insert, delete and display the details of a 26-29
student such as roll_no, sname and course using Stack.
17. Write a menu driven program which insert, delete and display the details of a movie such as 29-32
movie_id, mname and rating using Stack.
18. Write a menu driven program which insert, delete and display the details of a product such as 32-35
pid, pname and price using Stack
19. Write a menu driven program which insert, delete and display the details of a club such as 35-37
club_id, cname and city using Stack.
GSBV,BURARI 2 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
20. Write a menu driven program to demonstrate add, display, update, delete and exit. Performed on a 38-42
table Book containing (bid, bname, bprice) through python-MySql connectivity
21. Write a menu driven program to demonstrate add, display, update, delete and exit. Performed on 42-46
a table Product containing (pid, pname, price) through python-MySql connectivity.
22. Write a menu driven program to demonstrate add, display, update, delete and exit. Performed on a 46-50
table club containing (club_id, cname, city) through python-MySql connectivity
23. Write a menu driven program to demonstrate add, display, update, delete and exit. Performed on a 50-55
table student containing (sid, sname, course) through python-MySql connectivity.
24. Write a menu driven program to demonstrate add, display, update, delete and exit. Performed on a 55-59
table movie containing (mid, mname, rating) through python-MySql connectivity
25. Write a menu driven program to demonstrate add, display, update, delete and exit. Performed on a 59-64
table Employee containing (eid, ename, salary) through python-MySql connectivity
MYSQL QUERIES
1. Create a database 65
2. To create a student table with the student id, class, section, gender, name, dob, and marks as 66
attributes where the student id is the primary key.
5. To increase the marks by 5% for those students who are scoring marks more than 30 . 68
6. To display the entire content of the table. 68
7. To display student_id, name and marks of those students who are scoring marks more than 30. 69
12. To display the information of all the students, whose name starts with ‘S’ 72
13. To display the student_id, name, dob of those students who are born between ‘2005-01-01’ and 72
‘2005-12-31’
14. To display the student_id, name, dob, marks, email of male students in ascending order of their name 73
15. To display the student_id, gender, name, dob, marks, email of students in descending order of their marks. 74
16. To display the unique section name from the student table 74
17. Create a student table with student id, name and marks as attribute, where the student id is the 75
Primary key
GSBV,BURARI 3 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
PYTHON PROGRAMS
Practical No-1: WAP in Python to Find the Factorial of a number using function.
def fact(n):
f=1
while(n>0):
f=f*n
n=n-1
return f
n=int(input("Enter a number to find the factorial: "))
if(n<0):
print("Factorial of -ive number is not possible")
elif(n==0):
print("Factorial of 0 is 1")
else:
factorial=fact(n)
print("Factorial of ",n," is =",factorial)
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Enter a number to find the factorial: 5
Factorial of 5 is = 120
>>>
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Enter a number to find the factorial: 0
Factorial of 0 is 1
GSBV,BURARI 4 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
>>>
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
>>>
#Default Parameter
def show(a,b,c=8):
print("Sum=",(a+b+c))
show(5,6)
show(5,6,10)
def show1(a,b=9,c=8):
print("Sum1=",(a+b+c))
show1(5)
show1(5,6)
show1(5,6,10)
#Positional Parameter
def show2(a,b):
print("Sub=",(a-b))
show2(15,6)
show2(6,15)
GSBV,BURARI 5 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
OUTPUT:
>>>
=RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Sum= 19
Sum= 21
Sum1= 22
Sum1= 19
Sum1= 21
Sub= 9
Sub= -9
>>>
Practical No-3: Write a program in Python to input the value of x and n and print
the sum of the following series
1+x+x^2+x^3+-----------x^n
x=int(input("Enter the value of x: "))
sum=0
for i in range(0,n+1):
sum=sum+x**i
print("Sum of series=",sum)
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Sum of series= 85
GSBV,BURARI 6 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-4:WAP in python to read a text file and print the number of vowels
and consonants in the file
f=open("Vowel.txt","r")
Data=f.read()
V=['A','E','I','O','U','a','e','i','o','u']
C=['B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X', \
'Y','Z','b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v',' w', \
'x','y','z']
cv=0
cc=0
for i in data:
if i in V:
cv=cv+1
elif i in C:
cc=cc+1
ct=0
for i in data:
ct=ct+1
f.close()
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Practical No-5: WAP in Python to read a text file and print the line or
paragraph starting with the letter ‘S’.
GSBV,BURARI 7 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
f=open("abc.txt","r")
line=f.readline()
lc=0
while line:
if line[0]=='s' or line[0]=='S':
print(line,end="")
lc=lc+1
line=f.readline()
f.close()
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Sam
Sameer
Sanjay
Sunil
Practical No-6: WAP in Python to read a text file and print the number of
uppercase and lowercase letters in the file.
GSBV,BURARI 8 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
f=open("Vowel.txt","r")
data=f.read()
U=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R', \
'S','T','U','V','W','X','Y','Z',]
L=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r', \
's','t','u','v','w','x','y','z']
cu=0
cl=0
for i in data:
if i in U:
cu=cu+1
elif i in L:
cl=cl+1
ct=0
for i in data:
ct=ct+1
print("Number of Uppercase letters in the file=",cu)
print("Number of Lowercase Letters in the file=",cl)
f.close()
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 9 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-7: WAP in Python to create a binary file with name and roll number of the students.
Search for a given roll number and display the name of student.
import pickle
S={}
f=open('stud.dat','wb')
c='y'
S['RollNo']=rno
S['Name']=name
pickle.dump(S,f)
f.close()
f=open('stud.dat','rb')
rno=int(input("Enter the roll no. of the student to be search: "))
K={}
m=0
try:
while True:
K=pickle.load(f)
if K["RollNo"] == rno:
print(K)
m=m+1
except EOFError:
f.close()
if m==0:
GSBV,BURARI 10 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Practical No-8: Create a binary file with roll_no, name and marks of some students and update the
marks of specific student.
import pickle
S={}
f=open('stud.dat','wb')
c='y'
S['RollNo']=rno
S['Name']=name
S['Marks']=marks
pickle.dump(S,f)
GSBV,BURARI 11 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
f.close()
f=open('stud.dat','rb+')
try:
while True:
pos=f.tell()
S=pickle.load(f)
if S["RollNo"] == rno:
f.seek(pos)
S["Marks"]=marks
pickle.dump(S,f)
m=m+1
except EOFError:
f.close()
if m==0:
else:
f=open('stud.dat','rb')
try:
while True:
S=pickle.load(f)
print(S)
except EOFError:
f.close()
GSBV,BURARI 12 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Practical No-9: Create a binary file with eid, ename and salary and update the salary of the employee
import pickle
E={}
f=open('emp.dat','wb')
c='y'
GSBV,BURARI 13 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
E['Emp_Id']=eid
E['Emp_Name']=ename
E['Salary']=salary
pickle.dump(E,f)
c=input("Do You Want to add more employee(y/n): ")
f.close()
f=open('emp.dat','rb+')
f.seek(0,0)
m=0
try:
while True:
pos=f.tell()
E=pickle.load(f)
if E["Emp_Id"] == eid:
f.seek(pos)
E["Salary"]=salary
pickle.dump(E,f)
m=m+1
except EOFError:
f.close()
if m==0:
else:
f=open('emp.dat','rb')
GSBV,BURARI 14 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
try:
while True:
E=pickle.load(f)
print(E)
except EOFError:
f.close()
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 15 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-10: Create a text file and remove the lines from the file which contains letter ‘K’
import sys
f=open("sps.txt","w+")
data = sys.stdin.readlines()
for i in data:
f.write(i)
f.close()
print("**********")
print("Content of File: ")
f=open("sps.txt","r")
data=f.read()
print(data)
f.close()
f=open("sps.txt","r+")
data=f.readlines()
f.seek(0)
for i in data:
if "K" not in i:
f.write(i)
f.truncate()
f.close()
print("**********")
f=open("sps.txt","r")
data=f.read()
print(data)
GSBV,BURARI 16 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
S P SHARMA CLASSES
HELLO INDIA
KARAN
SAM
RAM
KASHMIR
DELHI
**********
Content of File:
S P SHARMA CLASSES
HELLO INDIA
KARAN
SAM
RAM
KASHMIR
DELHI
**********
S P SHARMA CLASSES
HELLO INDIA
SAM
RAM
DELHI
GSBV,BURARI 17 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-11: Create a binary file with 10 random numbers from 1 to 40 and print those numbers.
import pickle,random
N=[]
f=open("sps.txt","wb")
for i in range(10):
N.append(random.randint(1,40))
pickle.dump(N,f)
f.close()
print("File Created:")
print("Content of File:")
f=open("sps.txt","rb")
data=pickle.load(f)
for i in data:
print(i)
f.close()
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
File Created:
Content of File:
24
14
18
14
26
9
33
7
10
33
GSBV,BURARI 18 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-12: Write a program in Python to create a CSV file with the details of 5 students.
import csv
f=open("student.csv","w",newline='')
cw=csv.writer(f)
cw.writerow(['Rollno','Name','Marks'])
for i in range(5):
sr=[rollno,name,marks]
cw.writerow(sr)
f.close()
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Student Record of 1
Enter Marks: 34
Student Record of 2
Enter Marks: 37
GSBV,BURARI 19 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Student Record of 3
Enter Marks: 24
Student Record of 4
Enter Marks: 40
Student Record of 5
Enter Marks: 37
import csv
f=open("student.csv","r")
cr=csv.reader(f)
for r in cr:
print(r)
f.close()
GSBV,BURARI 20 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Practical No-14: Write a menu driven program which insert, delete and display the details of an
employee such as eid, ename and salary using Stack .
Employee=[]
c='y'
while(c=="y" or c=="Y"):
print("1: Add Employee Detail: ")
print("2: Delete Employee Detail: ")
print("3: Display Employee Detail: ")
choice=int(input("Enter your choice: "))
if(choice==1):
eid=int(input("Enter Employee Id: "))
ename=input("Enter Employee Name: ")
salary=float(input("Enter Employee Salary: "))
emp=(eid,ename,salary)
Employee.append(emp)
elif(choice==2):
if(Employee==[]):
print("Stack Empty")
else:
print("Deleted element is: ",Employee.pop())
elif(choice==3):
L=len(Employee)
while(L>0):
print(Employee[L-1])
L=L-1
else:
print("Wrong Input")
c=input("Do you want to continue? Press 'y' to Continue: ")
GSBV,BURARI 21 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
OUTPUT:
GSBV,BURARI 22 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-15: Write a menu driven program which insert, delete and display the details of a book
such as book_id, book_name and price using Stack
GSBV,BURARI 23 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Book=[]
c='y'
while(c=='y' or c=='Y'):
if(choice==1):
B=(book_id,book_name,price)
Book.append(B)
elif(choice==2):
if(Book==[]):
print("Stack Empty")
else:
elif(choice==3):
L=len(Book)
while(L>0):
print(Book [L-1])
L=L-1
else:
print("Wrong Input")
GSBV,BURARI 24 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 25 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-16: Write a menu driven program which insert, delete and display the details of a
student such as roll_no, sname and course using Stack.
Student=[]
c='y'
while(c=='y' or c=='Y'):
GSBV,BURARI 26 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
if(choice==1):
Student.append(stu)
elif(choice==2):
if(Student==[]):
print("Stack Empty")
else:
elif(choice==3):
L=len(Student)
while(L>0):
print(Student[L-1])
L=L-1
else:
print("wrong input")
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 27 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 28 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-17: Write a menu driven program which insert, delete and display the details of a
movie such as movie_id, mname and rating using Stack.
movie=[]
c='y'
while(c=='y' or c=='Y'):
if(Choice==1):
GSBV,BURARI 29 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
mov= (mid,mname,rating)
movie.append(mov)
elif(Choice==2):
if(movie==[]):
print("stack empty")
else:
elif(Choice==3):
L=len(movie)
while(L>0):
print(movie[L-1])
L=L-1
else:
print("wrong input")
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 30 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 31 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-18: Write a menu driven program which insert, delete and display the details of a
product such as pid, pname and price using Stack
Product=[ ]
c="y"
while(c=="y" or c=="Y"):
if(choice==1):
Prd=(pid,pname,price)
Product.append(Prd)
elif(choice==2):
GSBV,BURARI 32 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
if(Product==[ ]):
print("Stack Empty")
else:
elif(choice==3):
L=len(Product)
while(L>0):
print(Product[L-1])
L=L-1
else:
print("Wrong input")
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 33 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 34 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-19: Write a menu driven program which insert, delete and display the details of a club
such as club_id, cname and city using Stack.
Club= []
c='y'
if (choice == 1):
clu = (cid,cname,city)
Club.append(clu)
elif (choice==2):
if(Club == []):
else:
GSBV,BURARI 35 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
L = len(Club)
while (L>0):
print(Club[L-1])
L=L-1
else:
print("Wrong Input")
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
Enter choice: 1
Enter choice: 1
GSBV,BURARI 36 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Enter choice: 1
Enter choice: 3
Enter choice: 2
Enter choice: 3
GSBV,BURARI 37 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-20: Write a menu driven program to demonstrate add, display, update, delete and exit.
Performed on a table Book containing (bid, bname, bprice) through python-MySql connectivity
import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="r
oot")
mycursor=con.cursor()
mycursor.execute("use spsharmag")
float(5,2))")
c="y"
while(c=="y" or c=="Y"):
if(choice==1):
con.commit()
elif(choice==2):
GSBV,BURARI 38 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
mybooks=mycursor.fetchall()
for x in mybooks:
print(x)
elif(choice==3):
bid=%s",(bname,bprice,bid))
con.commit()
elif(choice==4):
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 39 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 40 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 41 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-21: Write a menu driven program to demonstrate add, display, update, delete and exit.
Performed on a table Product containing (pid, pname, price) through python-MySql connectivity.
import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="r
oot")
mycursor=con.cursor()
mycursor.execute("use spsharmag")
varchar(20),pprice float(8,2))")
c="y"
while(c=="y" or c=="Y"):
GSBV,BURARI 42 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
if(choice==1):
con.commit()
elif(choice==2):
myproducts=mycursor.fetchall()
for x in myproducts:
print(x)
elif(choice==3):
pid=%s",(pname,pprice,pid))
con.commit()
elif(choice==4):
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
GSBV,BURARI 43 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 44 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 45 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practical No-22: Write a menu driven program to demonstrate add, display, update, delete and exit.
Performed on a table club containing (club_id, cname, city) through python-MySql connectivity
import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="r
oot")
mycursor=con.cursor()
mycursor.execute("use spsharmag")
mycursor.execute("create table if not exists club (cid int primary
key, cname
varchar(20),city varchar(20))")
c="y"
GSBV,BURARI 46 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
while(c=="y" or c=="Y"):
if(choice==1):
cid=int(input("Enter club Id: "))
cname=input("Enter club Name: ")
city=input("Enter club city: ")
elif(choice==2):
myclubs=mycursor.fetchall()
for x in myclubs:
print(x)
elif(choice==3):
con.commit()
elif(choice==4):
GSBV,BURARI 47 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 48 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 49 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practicle No 23: Write a menu driven program to demonstrate add, display, update, delete and exit.
Performed on a table student containing (sid, sname, course) through python-MySql connectivity.
GSBV,BURARI 50 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="r
oot")
mycursor=con.cursor()
mycursor.execute("use spsharmag")
course varchar(20))")
c="y"
while(c=="y" or c=="Y"):
if(choice==1):
con.commit()
elif(choice==2):
mystudents=mycursor.fetchall()
for x in mystudents:
GSBV,BURARI 51 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
print(x)
elif(choice==3):
sid=%s",(sname,course,sid))
con.commit()
elif(choice==4):
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 52 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 53 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 54 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practicle No 24: Write a menu driven program to demonstrate add, display, update, delete and exit.
Performed on a table movie containing (mid, mname, rating) through python-MySql connectivity
import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="r
oot")
mycursor=con.cursor()
mycursor.execute("use spsharmag")
varchar(20),rating float(5,2))")
c="y"
while(c=="y" or c=="Y"):
GSBV,BURARI 55 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
if(choice==1):
con.commit()
elif(choice==2):
mymovies=mycursor.fetchall()
for x in mymovies:
print(x)
elif(choice==3):
mid=%s",(mname,rating,mid))
con.commit()
elif(choice==4):
GSBV,BURARI 56 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
OUTPUT:
= RESTART: C:\Users\UJJWAL\AppData\Local\Programs\Python\Python38-32\P-4.py
GSBV,BURARI 57 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 58 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
Practicle No 25: Write a menu driven program to demonstrate add, display, update, delete and exit.
Performed on a table Employee containing (eid, ename, salary) through python-MySql connectivity
import mysql.connector
con=mysql.connector.connect(host="localhost",username="root",passwd="r
oot")
mycursor=con.cursor()
mycursor.execute("use spsharmag")
GSBV,BURARI 59 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
salary float(8,2))")
c="y"
while(c=="y" or c=="Y"):
if(choice==1):
con.commit()
elif(choice==2):
myemp=mycursor.fetchall()
for x in myemp:
print(x)
elif(choice==3):
GSBV,BURARI 60 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
eid=%s",(ename,salary,eid))
con.commit()
elif(choice==4):
con.commit()
elif(choice==5):
break
else:
print("Wrong Choice")
OUTPUT:
= RESTART:C:/Users/UJJWAL/AppData/Local/Programs/Python/Python38-
32/Practical_25.py
GSBV,BURARI 61 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 62 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 63 DAVID
CS Practical File Session 2023-2024 CLASS 12 th
GSBV,BURARI 64 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
MYSQL QUERIES
Q – 1: Create a database
Syntax:
GSBV,BURARI 65 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
Q – 2: To create a student table with the student id, class, section, gender, name, dob, and marks as
attributes where the student id iss the primary key
Primary key is a constraint of an attribute which cannot be NULL or duplicate. Only one primary
key is allowed in a table.
Syntax:
GSBV,BURARI 66 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
To delete the specific record from the table use delete command/query.
Syntax:
Note: If we don’t use where clause It delete all the records one by on
onee from the table
GSBV,BURARI 67 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
Q – 5: To increase the marks by 5% for those students who are scoring marks more than 30.
Syntax
GSBV,BURARI 68 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
Q – 7: To display student_id, name and marks of those students who are scoring marks more than
30.
Aggregate Function:
5 Aggregate function in SQL:
1. SUM() : Find the sum of the values of specific column
2. MAX() : Find the maximum value from the specific column
3. MIN() : Find the minimum value from the specific column
4. AVG() : Find the average of all values from the sp
specific column
5. COUNT() : Count the value from the specific column
GSBV,BURARI 69 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
Q – 10: To add a new column email in the student table with appropriate data type.
type
GSBV,BURARI 70 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
Q – 11: To add the email id’ss of each student in the previously created email column.
GSBV,BURARI 71 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
Q – 12: To display the information of all the students, whose name starts with ‘S’
‘S’.
Q – 13: To display the student_id, name, dob of those students who are born between ‘2005-01-01’
‘2005
and ‘2005-12-31’.
GSBV,BURARI 72 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
Q – 14: To display the student_id, name, dob, marks, email of male students in ascending order of
their name.
GSBV,BURARI 73 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
Q – 15: To display the student_id, gender, name, dob, marks, email of students in descending order
of their marks.
Q – 16: To display the unique section name from the student table.
GSBV,BURARI 74 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
Q – 17: Create a student table with student id, name and marks as attribute, where the student id is
the primary key.
GSBV,BURARI 75 DAVID
CS Practical File Session 2023
2023-2024 CLASS 12th
Q –20:
20: Use the Select command to get the details of the students with marks more than 30.
30
GSBV,BURARI 76 DAVID