0% found this document useful (0 votes)
8 views52 pages

Practicle File

The document is a practical file for a computer science project completed by Chaitanya V. Pachbhai at Ambuja Vidya Niketan, under the guidance of Mr. Ravi Kumar Sharma. It includes a certificate of completion, acknowledgments, and a detailed table of contents listing various programming tasks and their respective pages. The tasks cover a range of programming concepts, including functions, file handling, and data manipulation using Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views52 pages

Practicle File

The document is a practical file for a computer science project completed by Chaitanya V. Pachbhai at Ambuja Vidya Niketan, under the guidance of Mr. Ravi Kumar Sharma. It includes a certificate of completion, acknowledgments, and a detailed table of contents listing various programming tasks and their respective pages. The tasks cover a range of programming concepts, including functions, file handling, and data manipulation using Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

AMBUJA VIDYA NIKETAN

UPPARWAHI

COMPUTER SCIENCE
PRACTICLE FILE

INSTRUCTED BY PRESENTED BY

Mr. RAVI KUMAR SHARMA Chaitanya V. Pachbhai


CERTIFICATE
This is to certify that Chaitanya V. Pachbhai
of class XII (Commerce) of Ambuja Vidya
Niketan has successfully completed the computer
science “PRACTICLE FILE” prescribed by
Mr. RAVI KUMAR SHARMA , during the
academic session 2024-25 as per guidelines issued
by Central Board Of Secondary Education .

Internal’s signature External’s signature

Principal’s signature School stamp


ACKNOWLEDGMENT
I am very grateful to everyone who supported
me to complete my project on time. Then I
would like to thank our esteemed principal sir
Mr. Rajesh Sharma for his co-ordination and
support.
I would like to express my deepest gratitude to
my teacher Mr. Ravi Kumar Sharma, for their
unwavering support and guidance throughout
this project. Your insightful feedback and
encouragement have been invaluable, and I have
learned so much under your mentorship. Your
dedication to teaching and your passion for the
subject have truly inspired me. Thank you for
always being there to help and for believing in
my potential.
Secondly, I would also like to thank my parents
and friends who helped me a lot in finishing the
project within the limited time
I am making this project not only for marks but
also to increase my knowledge.
THANKS AGAIN TO ALL WHO HELPED ME
CONTENT
Sr Particulars Page Sig.
no. No.
1. WRITE A PROGRAM TO FIND A 8
FACTORIAL OF A NO. USING
FUNCTION
2. WRITE A PROGRAM TO TAKE An 9
INPUT IN 2 LISTS AND PRINT THE
SUM OF ELEMENT OF BOTH THE
LIST
3. WRITE A PROGRAM TO PRINT 11
FIBONNACI SERIES USING
FUNCTION
4. WRITE A PROGRAM TO READ A 12
TEXT FILE AND DISPLAY THE
EACH WORD OF TEXT FILE
SEPERATED BY ‘#’
5. WRITE A PROGRAM TO COUNT 13
THE NUMBER OF VOWELS,
CONSONANTS, UPARCASE AND
LOWERCASE LETTER IN A TEXT
FILE
6. WRITE A PROGRAM TO COUNT 15
THE NUMBER OF WORDS IN A
TEXT FILE
7. WRITE A PROGRAM TO FIND THE 16
OCCURANCE OF ‘THE’ IN A TEXT
FILE
8. WRITE A PROGRAM TO COUNT 17
NUMBER OF LINES STARTING
WITH ‘A’ OR ‘H’ IN A TEXT FILE
9. Write a program in csv file(student.csv) 18
THE FILE CONTAINING The records
in following order (student_id ,
student_name , marks , class)TO
INPUT THE ROLL Number from the
user and display the corresponding
record from csv file
10.Write a program in csv file(student.csv) 19
to change the marks of the student by
10% who has got more than 45%
11.Write a program in binary 21
file(student.dat) THE FILE
CONTAINING The records in
following order (student_id ,
student_name , marks , class)TO
INPUT THE ROLL Number from the
user and display the corresponding
record from binary file
12.Write a program in binary 22
file(student.dat) to change the marks of
the student by 10% who has got more
than 45%
13.Write a program to delete all the line 24
starting with ‘a’ from the text file

14.Write a program to input a list of 10 26


no. and swap the element with its
neighbor
15.Write a program to input a list of 10 27
no. and sort the element using bubble
sort
16.Write a program to input a list of 10no. 29
and sort the element using insertion
sort
17.Write a program to input a list of 10 30
no. and search any number using linear
search
18.Write a program to input 10 no. in a 31
list and find the smallest and the
greatest number among them
19.Write a program to Implement a stack 32
of a number.

20.Write a program to create a list of 36


dictionaries with key values (id, name,
marks, class) enter 10 records in the list
and print the record of the student who
has got more than 80 marks
21.MySQL connectivity- TO SHOW THE 38
DETAILS OF THE TABLE WHERE
BOOK NAME IS SPECIFED
22.To insert a record in a table 39

23.To delete a record from the table 40

24.To update the record of the table 41

25.To display the records of the table 42

26.To display particular records of the 43


table
27.To search the record of the table 44

28.MYSQL Queries 46
Q1. WRITE A PROGRAM TO FIND A
FACTORIAL OF A NO. USING FUNCTION?
def Factorial():
ans='y'
a=1
while ans =='y':
n=int(input("Enter A Number To Find The Factorial Of A
Number :"))
while n>0:
a=a*n
n=n-1
print("Factorial Of Number That You Insert Is",a)
ans=input("Do Yo Want To Continue(y/n)")
Factorial()
Q2. WRITE A PROGRAM TO TAKE An INPUT
IN 2 LISTS AND PRINT THE SUM OF
ELEMENT OF BOTH THE LIST?
n=int(input("Enter How Many Number You Have To Enter In
The List:"))
ans='y'
t=0
L1=[]
L2=[]
L3=[]
while ans =='y':
for i in range(0,n):
a=int(input("Enter The Number For List 1:"))
L1.append(a)
print(L1)
for j in range(0,n):
b=int(input("Enter The Number For List 2:"))
L2.append(b)
print(L2)
for k in range(0,n):
t=L1[k]+L2[k]
L3.append(t)
print("Sum Of Two Lists:",L3)
ans=input("Do Yo Want To Continue(y/n)")
Q3. WRITE A PROGRAM TO PRINT
FIBONNACI SERIES USING FUNCTION?
n=int(input("Enter The Number For Fibonacci Series:"))
n1,n2=0,1
print("Fibonacci Series:",n1,n2,end=' ')
for i in range(2,n):
n3=n1+n2
n1=n2
n2=n3
print(n3,end=' ')
Q4. WRITE A PROGRAM TO READ A TEXT
FILE AND DISPLAY THE EACH WORD OF
TEXT FILE SEPERATED BY ‘#’?
f=open("story.txt","r")
x=f.read()
str=x.split()
for i in str:
print(i,end='#')
f.close()
Q5. WRITE A PROGRAM TO COUNT THE
NUMBER OF VOWELS, CONSONANTS,
UPARCASE AND LOWERCASE LETTER IN
A TEXT FILE?
f=open("story.txt","r")
a=0
b=0
c=0
count=0
x=f.read()
print(x)
for i in x:
if i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or
i=='E' or i=='I' or i=='O' or i=='U':
count=count+1
else:
a=a+1
for z in x:
if z.isupper():
b=b+1
else:
c=c+1
print("Occurance Of Vowels:",count)
print("Occurance Of Consonants:",a)
print("Occurance Of Uppercase",b)
print("Occurance Of Lowercase",c)
f.close()
Q6. WRITE A PROGRAM TO COUNT THE
NUMBER OF WORDS IN A TEXT FILE?
def CountWord():
f=open("story.txt","r")
x=f.read()
print(x)
l=x.split()
print("Number Of Words In Text File:",len(l))
f.close()
CountWord()
Q7. WRITE A PROGRAM TO FIND THE
OCCURANCE OF ‘THE’ IN A TEXT FILE?
def Word_The():
f=open("story.txt","r")
c=0
x=f.read()
print(x)
l=x.split()
for i in l:
if i in "the,The":
c=c+1
print("Occurance Of Word The:",c)
f.close()
Word_The()
Q8. WRITE A PROGRAM TO COUNT NUMBER
OF LINES STARTING WITH ‘A’ OR ‘H’ IN A
TEXT FILE?
def CountLine():
z=open("story.txt","r")
l=z.read()
print(l)
f=open("story.txt","r")
c=0
x=f.readlines()
for i in x:
if i[0]=='a' or i[0]=='h' or i[0]=='A' or i[0]=='H':
c=c+1
print("Number Of Lines Starting With A or H:",c)
f.close()
CountLine()

Q9. Write a program in csv file(student.csv) THE


FILE CONTAINING The records in following
order (student_id , student_name , marks ,
class)TO INPUT THE ROLL Number from the
user and display the corresponding record from
csv file?
import csv
def search():
ch='y'
while ch=='y':
f=open("student.csv","r")
a=csv.reader(f)
r=input("Enter Student Roll No to Serach")
for l in a:
if l[0]==r:
print(l)
ch=input('do you want to countinue(y/n)')
break
f.close()
search()

Q10.Write a program in csv file(student.csv) to


change the marks of the student by 10% who
has got more than 45%?
def change():
import os
import csv
d={}
f=open('student.csv','r')
g=open('temp.csv','w')
d=csv.reader(f)
if d["marks"]>45:
d["marks"]=d["marks"]+d["marks"]*0.1
print(d,g)
except EOFError:
f.close()
g.close()
os.remove('student.csv')
os.rename('temp.csv','student.csv')

a=int(input('enter 1 for changing the marks and 2 for


viewing the changed result:'))
if a==1:
change()
if a==2:
import csv
f=open('student.csv','rb')
d=[]
try:
while True:
d=csv.reader(f)
print(d)
except EOFError:
f.close()
b=input('press y for countinue and n for exit:')
if b=='n':
break

Q11.Write a program in binary file(student.dat)


THE FILE CONTAINING The records in
following order (student_id , student_name ,
marks , class)TO INPUT THE ROLL Number
from the user and display the corresponding
record from binary file?
import csv
def search():
f=open("student.csv","r")
a=csv.reader(f)
r=input("enter roll no to search")
for l in a:
if l[0]==r:
print(l)
break
f.close()
search()

Q12.Write a program in binary file(student.dat) to


change the marks of the student by 10% who
has got more than 45%?
def change():
import os
import pickle
d={}
f=open(“student.dat”,”rb”)
g=open(“temp.dat”,”wb”)
try:
while True:
d=pickle.load(f)
if d["marks"]>45:
d["marks"]=d["marks"]+d["marks"]*0.1
pickle.dump(d,g)
except EOFError:
f.close()
g.close()
os.remove('student.dat')
os.rename('temp.dat','student.dat')
while True:
a=int(input('enter 1 for changing the marks and 2 for
viewing the changed result:'))
if a==1:
change()
if a==2:
import pickle
f=open(“student.dat”,”rb”)
d=[]
try:
while True:
d=pickle.load(f)
print(d)
except EOFError:
f.close()
b=input(“Press y for countinue and n for exit:”)
if b=='n':
break

Q13.Write a program to delete all the line starting


with ‘a’ from the text file?
def dele():
f=open(“story.txt”,”r”)
f1=open(“storynew.txt”,”w”)
g=open(“temp.txt”,”w”)
x=f.readlines()
for i in x:
if i[0]=='a' or i[0]=='A':
g.write(i)
else:
f1.write(i)
print(“Updated successfully”)
def show():
p=open('temp.txt','r')
z=p.read()
print(z)
def show2():
n=open('storynew.txt','r')
l=n.read()
print(l)
while True:
ch=int(input(“press 1 to update press 2 to get the
deleted line press 3 to get the uptades file and press
4 to exit :”))
if ch==1:
dele()
if ch==2:
show()
if ch==3:
show2()
if ch==4:
break

Q14.Write a program to input a list of 10 no. and


swap the element with its neighbor?
def swap(l):
for i in range(0,len(l)-1,2):
l[i],l[i+1]=l[i+1],l[i]
print(l)
n=[]
for j in range(0,10):
a=int(input(“Enter the number for the list:”))
n.append(a)
swap(n)

Q15.Write a program to input a list of 10 no. and


sort the element using bubble sort?
def Ascsort(l):
for i in range(0,len(l)):
for j in range(i+1,len(l)):
if l[i]>l[j]:
t=l[i]
l[i]=l[j]
l[j]=t
print(“list in ascending order:”,l)
def Dscsort(l):
for i in range(0,len(l)):
for j in range(i+1,len(l)):
if l[i]<l[j]:
t=l[i]
l[i]=l[j]
l[j]=t
print(“list in descending order:”,l)
while True:
l=eval(input('enter the list:'))
ch=int(input(“Enter 1 for Arranging your list to
Ascending order or else enter 2 for Arrannging your
list to Descending order:”))
if ch==1:
ascsort(l)
if ch==2:
dscsort(l)
a=input(“Enter do you want to continue this
process(y/n)?”)
if a=='n':
break

Q16.Write a program to input a list of 10no. and


sort the element using insertion sort?
def Insertsort():
n=eval(input(“Enter a list of 10 number:”))
if len(n)==10:
for i in range(1,len(n)):
b=n[i]
j=i-1
while j>=0 and b<n[j]:
n[j+1]=n[j]
j=j-1
else:
n[j+1]=b
print(“Insertion sort=”,n)
else:
print(“please enter a list of 10 numbers!”)
Insertsort()

Q17.Write a program to input a list of 10 no. and


search any number using linear search?
def Position():
l=eval(input("Enter a list :"))
p=int(input("Enter a number to search :"))
a=0
for i in range(len(l)):
if l[i]==p:
a=1
pos=i+1
break
if a==1:
print("Element found at',pos,'position")
else:
print("Element not found")
Position()

Q18.Write a program to input 10 no. in a list and


find the smallest and the greatest number
among them?
def number():
n=int(input("Enter the 1st number :"))
maxi=n
mini=n
for i in range(0,9):
n=int(input("Enter the next number :"))
if n>maxi:
maxi=n
if n<mini:
mini=n
print("Maximum number is :",maxi)
print("Minimum number is :",mini)
number()

Q19.Write a program to Implement a stack of a


number.
def isempty(stk):
if stk==[]:
return True
else:
return False
def Push(stk,item):
stk.append(item)
top=len(stk)-1
def Pop(stk):
if isempty(stk):
return"Underflow"
else:
item=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)-1
return item
def Peek(stk):
if isempty(stk):
return"Underflow"
else:
top=len(stk)-1
return stk[top]
def Display(stk):
if isempty(stk):
print("Stack is Empty")
else:
top=len(stk)-1
print(stk[top],"<-top")
for a in range(top-1,-1,-1):
print(stk[a])
stack=[]
top=None
while True:
print("STACK OPERATIONS")
print("1:Push")
print("2:Pop")
print("3:Peek")
print("4:Display Stack")
print("5:Exit")
ch=int(input('enter your choice(1-5):'))
if ch==1:
item=int(input("Enter Item:"))
Push(stack,item)
elif ch==2:
item=Pop(stack)
if item=="Underflow":
print("Underflow! stack is empty!")
else:
print('popped item is',item)
elif ch==3:
item=Peek(stack)
if item=="Underflow":
print("Underflow! stack is empty!")
else:
print('topmost item is',item)
elif ch==4:
Display(stack)
elif ch==5:
break
else:
print("Invalid Choice!")
Q20.Write a program to create a list of dictionaries
with key values (id, name, marks, class) enter 10
records in the list and print the record of the
student who has got more than 80 marks?
def Add():
l=[]
for i in range(10):
d={}
i=int(input("Enter the Id of the student:"))
n=input("Enter the name of the student:")
m=int(input("Enter the marks of the student:"))
c=int(input("Enter the class of the student:"))
d['roll no']=i
d['name']=n
d['marks']=m
d['class']=c
l.append(d)
for x in l:
if x['marks']>=80:
print("Records of students who has got more than
80 marks :",x)
Add()
MySQL Connectivity
Q21.TO SHOW THE DETAILS OF THE TABLE
WHERE BOOK NAME IS SPECIFED?
import mysql.connector
def Search_Store():
ans='y'
while ans =='y':
con=mysql.connector.connect(host="localhost",user="r
oot",passwd="chaitanya",database="cp")
cur=con.cursor()
n=input("Enter The Book Name To Search")
cur.execute("select * from store where
ItName=%s",(n,))
for x in cur:
print(x)
ans=input("Do Yo Want To Continue(y/n)")
Search_Store()
Q1. To insert a record in a table?
import mysql.connector
def Add_Book():
ans='y'
while ans =='y':

con=mysql.connector.connect(host="localhost",use
r="root",passwd="chaitanya",database="cp")
cur=con.cursor()
no=int(input("Enter Book Number="))
na=input("Enter Book Name=")
sc=int(input("Enter Book Code="))
iq=int(input("Enter Book Quantity="))
cur.execute("insert into
store(ItNo,ItName,Stcode,ItQuantity)values(%s,%s,
%s,%s)",(no,na,sc,iq))
print("One Item Inserted Successfully")
ans=input("Do Yo Want To Continue(y/n)")
con.commit()
con.close()
Add_Book()
Q2. To delete a record from the table?
import mysql.connector
def Delete_Book():
ans='y'
while ans =='y':

con=mysql.connector.connect(host="localhost",use
r="root",passwd="chaitanya",database="cp")
cur=con.cursor()
r=input("Enter Book Name To Delete=")
cur.execute("delete from store where
ItName=%s",(r,))
print("Deleted Sucessfully")
ans=input("Do Yo Want To Continue(y/n)")
con.commit()
con.close()
Delete_Book()

Q3. To update the record of the table.


import mysql.connector
def Update_Book():
ans='y'
while ans =='y':

con=mysql.connector.connect(host="localhost",use
r="root",passwd="chaitanya",database="cp")
cur=con.cursor()
n=input("Enter Book Name To Update=")
q=int(input("Enter Book Quantity That Would Be
Updated="))
cur.execute("update store set ItQuantity=%s where
ItName=%s",(q,n))
print("Book Updated")
ans=input("Do Yo Want To Continue(y/n)")
con.commit()
con.close()
Update_Book()

Q4. To display the records of the table.


import mysql.connector
def Display_Books():
con=mysql.connector.connect(host="localhost",user="r
oot",passwd="chaitanya",database="cp")
cur=con.cursor()
cur.execute("select * from store order by ItNo asc")
for x in cur:
print(x)
Display_Books()
Q5. To display particular records of the table.
import mysql.connector
def Display_Store():
ans='y'
while ans =='y':

con=mysql.connector.connect(host="localhost",use
r="root",passwd="chaitanya",database="cp")
cur=con.cursor()
n=input("Enter The Book Name To Display")
cur.execute("select * from store where
ItName=%s",(n,))
for x in cur:
print(x)
ans=input("Do Yo Want To Continue(y/n)")
Display_Store()
Q6. To search the record of the table.
import mysql.connector
def Search_Store():
ans='y'
while ans =='y':

con=mysql.connector.connect(host="localhost",use
r="root",passwd="chaitanya",database="cp")
cur=con.cursor()
n=input("Enter The Book Name To Search")
cur.execute("select * from store where
ItName=%s",(n,))
for x in cur:
print(x)
ans=input("Do Yo Want To Continue(y/n)")
Search_Store()
MYSQL Queries
Q1. To show all the databases?

Q2. To show all the Tables?


Q3. To Display Store records?

Q4. To display in Descending order?

Q5. To display maximum Quantity of store?


Q6. To display minimum Quantity of store?

Q7. To display average Quantity of store?

Q8. To display Tolat Quantity of store?

Q9. To display particular record from store?


Q10. To display particular row from store?

Q11. To delete particular record from store?


Q12. To display count record in store?

Q13. To Create a database?

Q14. To Create a Table?

Q15. To insert a record in table?

Q16. To Delete a table?


Q17. To Delete a database?

Q18. To Update a record in Store?


Q19. To show the details of Table?

Q20. To Add a column in table store?

You might also like