Professional Documents
Culture Documents
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
if(n<0):
elif(n==0):
print("Factorial of 0 is 1")
else:
factorial=fact(n)
print("Factorial of",n,"is=",factorial)
OUTPUT:
CS Practical File Session 2023-24 CLASS 12
OUTPUT:
CS Practical File Session 2023-24 CLASS 12
print("Sum of series=",sum)
OUTPUT
CS Practical File Session 2023-24 CLASS 12
Practical No -4: WAP in Python to read a text file and print the number of vowels
and consonants in the file.
OUTPUT:
Practical No-5: WAP in Python to read a text file and print the line or paragraph
starting with the letter ‘S’.
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
sameer
samayra
sandhya
Saisa
Practical No-6: WAP in Python to read a text file and print the number of
uppercase and lowercase letters in the file.
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
f.close()
OUTPUT
CS Practical File Session 2023-24 CLASS 12
Practical No-6: WAP in Python to read a text file and print the number of
uppercase and lowercase letters in the file.
f=open("Vowel.txt","r")
data=f.read()
cu=0
cl=0
for i in data:
if i.isupper():
cu=cu+1
elif i.islower():
cl=cl+1
ct=0
for i in data:
ct=ct+1
OUTPUT
CS Practical File Session 2023-24 CLASS 12
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.
OUTPUT
CS Practical File Session 2023-24 CLASS 12
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)
f.close()
f=open('stud.dat','rb+')
f.seek(0,0)
m=0
CS Practical File Session 2023-24 CLASS 12
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()
OUTPUT
CS Practical File Session 2023-24 CLASS 12
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'
E['Emp_Id']=eid
E['Emp_Name']=ename
CS Practical File Session 2023-24 CLASS 12
E['Salary']=salary
pickle.dump(E,f)
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')
try:
while True:
E=pickle.load(f)
print(E)
except EOFError:
CS Practical File Session 2023-24 CLASS 12
f.close()
OUTPUT
Practical No-10 : Create a Binary File with 10 random numbers from 1 to 40 and
print those numbers.
import pickle,random
N=[]
f=open("abc.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("abc.txt","rb")
CS Practical File Session 2023-24 CLASS 12
data=pickle.load(f)
for i in data:
print(i)
f.close()
OUTPUT
CS Practical File Session 2023-24 CLASS 12
Practical No-11: WAP in Python to create a CSV file with the details of 5 students.
CS Practical File Session 2023-24 CLASS 12
import csv
f=open("student.csv","w",newline="")
cw=csv.writer(f)
cw.writerow(['Rollno','Name','Marks'])
for i in range(5):
name=input("Enter Name:")
marks=float(input("Enter Marks:"))
sr=[rollno,name,marks]
cw.writerow(sr)
f.close()
OUTPUT:
import csv
f=open("student.csv","r")
cr=csv.reader(f)
for r in cr:
print(r)
f.close()
OUTPUT
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.
CS Practical File Session 2023-24 CLASS 12
Employee=[]
c='y'
while(c=="y" or c=="Y"):
if(choice==1):
emp=(eid,ename,salary)
elif(choice==2):
if(Employee==[]):
print("Stack Empty")
else:
elif(choice==3):
L=len(Employee)
while(L>0):
print(Employee[L-1])
L=L-1
else:
print("Wrong Input")
OUTPUT
CS Practical File Session 2023-24 CLASS 12
CS Practical File Session 2023-24 CLASS 12
CS Practical File Session 2023-24 CLASS 12
def add_element():
emp=(empno,name,sal)
employee.append(emp)
def del_element():
if(employee==[]):
print("Underflow")
else:
empno,name,sal=employee.pop(0)
print("empno",empno,"name",name,"salary",sal)
def traverse():
if not (employee==[]):
n=len(employee)
for i in range(0,n):
print(employee[i])
else:
while True:
print("2.Delete employee")
print("3.Traversal")
print("4.Exit")
if(ch==1):
add_element()
elif(ch==2):
del_element()
elif(ch==3):
traverse()
elif(ch==4):
print("End")
break
else:
print("Invalid choice")
OUTPUT:
CS Practical File Session 2023-24 CLASS 12
i) Write the SQL Query to select all the customers that starts with the letter
“a”.
ii) Return all customers from a city that starts with ‘L’ followed by one
wildcard character, then ‘nd’ and then two wildcard characters.
CS Practical File Session 2023-24 CLASS 12
Employee(Code ,Name,Salary,Deptcode).
Write the SQL query to find the maximum salary department wise.
CS Practical File Session 2023-24 CLASS 12
Practical No-19: Write the SQL Query to increase 10% salary of the employee
whose experience is more than 3 year of the table Emp(Id, Name,Salary,exp).
CS Practical File Session 2023-24 CLASS 12
Practical No-20: Write the SQL query for Natural Join of two tables
Practical No:-21 Program to Search the particular record .If not found,display
appropriate message.
import mysql.connector
con=mysql.connector.connect(host='localhost',user='root',passwd='12345',
database='Document',charset='utf8')
if con.is_connected():
print("Connected..")
else:
print("Not Connected..")
cur=con.cursor()
while True:
found=0
s=input("Enter Stream..")
cur.execute(query)
data=cur.fetchall()
for i in data:
print(i)
found=1
if found==0:
if ch in 'Nn':
break
CS Practical File Session 2023-24 CLASS 12
OUTPUT