Practical No
Practical No
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
print("Factorial of 0 is 1")
else:
factorial=fact(n)
print("Factorial of",n,"is=",factorial)
OUTPUT:
CS Practical File CLASS 12
OUTPUT:
CS Practical File CLASS 12
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
print("Sum of series=",sum)
OUTPUT
CS Practical File 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:
Number of Vowels in the file= 1
Number of Consonants in the file= 35
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()
print("Total number of lines start with 's' or 'S' =",lc)
OUTPUT
sameer
samayra
sandhya
Saisa
Total number of lines start with 's' or 'S' = 4
CS Practical File 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()
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
CS Practical File 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 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 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'
while c=='y' or c=='Y':
S['Name']=name
S['Marks']=marks
pickle.dump(S,f)
c=input("Do You Want to add more students(y/n):")
f.close()
f=open('stud.dat','rb+')
rno=int(input("Enter the roll no. of the student to be updated:"))
marks=int(input("Enter the updated marks of the student:"))
f.seek(0,0)
m=0
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
CS Practical File CLASS 12
except EOFError:
f.close()
if m==0:
while True:
S=pickle.load(f)
print(S)
except EOFError:
f.close()
OUTPUT
CS Practical File 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
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+')
eid=int(input("Enter the Emp Id of the employee to be updated:"))
salary=float(input("Enter the Emp updated salary of the employee:"))
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
CS Practical File CLASS 12
pickle.dump(E,f)
m=m+1
except EOFError:
f.close()
if m==0:
print("Employee not Found")
else:
f=open('emp.dat','rb')
try:
while True:
E=pickle.load(f)
print(E)
except EOFError:
f.close()
OUTPUT
CS Practical File CLASS 12
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")
data=pickle.load(f)
for i in data:
print(i)
f.close()
CS Practical File CLASS 12
OUTPUT
CS Practical File CLASS 12
Practical No-11: WAP 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()
print("File Created Successfully")
OUTPUT:
CS Practical File CLASS 12
import csv
f=open("student.csv","r")
cr=csv.reader(f)
print("Content of CSV File:")
for r in cr:
print(r)
f.close()
OUTPUT
CS Practical File CLASS 12
Practical No-13: 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("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:")
CS Practical File CLASS 12
OUTPUT
CS Practical File CLASS 12
CS Practical File CLASS 12
Practical No-14: Create a student table and insert data. Implement the following SQL
commands on the student table:
o ALTER table to add new attributes / modify data type / drop attribute
o UPDATE table to modify data
o ORDER By to display data in ascending / descending order
o DELETE to remove tuple(s)
o GROUP BY and find the min, max, sum, count and average
o Joining Two or more Tables.
DATABASE MANAGEMENT
1.Create Database:
2.Use Database:
3.Create Table:
CS Practical File CLASS 12
4.Insert Command:
5.Select Command :
12.GROUP BY and find the min, max, sum, count and average
CS Practical File CLASS 12
CS Practical File CLASS 12
employee=[]
def add_element():
empno=input("Enter empno :")
name=input("Enter name :")
print("Underflow")
else:
empno,name,sal=employee.pop(0)
print("poped element is")
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:
print("Empty,No employee to display")
while True:
print("1.Add employee ")
print("2.Delete employee")
print("3.Traversal")
print("4.Exit")
ch=int(input("Enter your choice :"))
CS Practical File CLASS 12
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 CLASS 12
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 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 CLASS 12
Practical No-20: Write the SQL query for Natural Join of two tables
Bank_Account (Acode,Name,Type) and Branch(Acode,City).
CS Practical File CLASS 12
CS Practical File CLASS 12
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..")
query="Select*from student where stream='%s' "%s
cur.execute(query)
data=cur.fetchall()
for i in data:
print(i)
found=1
if found==0:
OUTPUT