0% found this document useful (0 votes)
17 views46 pages

Shashaa FINAL PRACTICAL

Uploaded by

kirenshashi50
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)
17 views46 pages

Shashaa FINAL PRACTICAL

Uploaded by

kirenshashi50
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/ 46

NAVKIS EDUCATIONAL

CENTRE

PRACTICAL FILE 2024-25

Computer Practical File


SUBMITTED BY -
NAME: Shashaank Ravi Patil
CLASS: XII
ACADEMIC YEAR: 2024-25
CERTIFICATE OF COMPLETION

This is to certify that Shashaank Ravi Patil,


student of Computer Science, Navkis
Educational Centre, have undergone the
completion of Practical File documentation
prescribed by the Central Board of Secondary
Education (CBSE) for the All India Senior
School Certificate Examination (AISSCE) for
the academic year 2024-2025.

SIGNATURE OF PRINCIPAL : ______________


SIGNATURE OF EXAMINER : ______________
REGISTRATION NUMBER : ______________
DATE OF SUBMISSION :____/_____/___
ACKNOWLEDGEMENT

We are deeply thankful to our school, Navkis Educational


Centre and Principal, Mrs. Seema Gupta , who has given us
this opportunity and encouragement to complete this Practical
File documentation.
We take this opportunity to acknowledge our computer
faculty Mrs. Asha for providing us with valuable support,
guidance and advice on planning and execution of the codes
and compilation of the Practical File.
We would like to thank our parents and friends for the smooth
completion and documentation of the Practical File for the
academic session 2024-25.
This Computer Science Practical File based on Python
programming language has been documented by Shashaank
Ravi Patil

NAME : Shashaank Ravi Patil


SIGNATURE : __________________
DATE : _____/______/______
PLACE : Navkis Educational Centre
INDEX
SL PROGRAMS PAGE
NO NO
PYTHON PGMS

1 Read a text file line by line and display 1


each word and separated by ‘#’
2 Read a text file and display the number of 2
consonants vowels ,upper case, lower case
3 Remove all the lines that contain the 3
character “a” in a file and write it to
another file
4 Create a binary file with a name and roll 4-6
number search for a given roll number
and display the appropriate message(list,
dictionary)
5 Create a binary file with a name and roll 7-9
number search for a given roll number
and marks and input a roll number and
update the marks (list ,dictionary)
6 Write a random number generator that 10
generates random numbers between 1 and
6 and stimulates a dice
7 Write a python program to implement 11-12
stack using list
8 Create a csv file by entering user id and 13-14
password ,read and search the password
for the given user id

9 WAP to print prime number between the 15


given range
10 WAP to print the fibonacci series 16
11 WAP to check if the given number is 17
Armstrong or not
12 Arithmetic operations 18-19
13 WAP to check if the element is present or 20
not(list)
14 WAP to swap even position numbers with 21
odd position and vice versa( using list)

15 WAP to print the name of the student 22


whose score more than 75 marks(using
dictionary)
MySQL Connectivity Programs
16 creating a python program to integrate 23-24
MySQL with python (creating database
and table )
17 To write a python program to integrate 25-26
MySQL with python by inserting records
to EMp table and display the records
18 Creating a python program to integrate 27
MySQL with python (searching and
displaying the records)
19 Creating python program to integrate 28-29
MySQL with python
(updating records)

SQL programs
20 SQL EXERCISE -1 30-31
21 SQL EXERCISE -2 32-33
22 SQL EXERCISE -3 34-35
23 SQL EXERCISE -4 36-37
24 SQL EXERCISE -5 38-40
1. Read a text file line by line and display each word and
separated by #

fp=open ("demo.txt","r")
lines=fp.readlines()
for line in lines:
words=line.split()
for word in words:
print(word+"#",end=" ")
print()
fp.close()

OUTPUT

The given file

1|P a ge
2. Read a text file and display the number of consonants vowels
,upper case, lower case

fp=open("sample text.txt","r")
v=c=low=up=0
word=fp.read()
for i in word :
if i.isalpha():
if i in 'aeiou AEIOU':
v=v+1
else:
c=c+1
if i.isupper():
up=up+1
else:
low=low+1
print("the number of vowels =",v)
print ("the number of consnants= ",c)
print("the number of lowercases= ",low)
print("the number of uppercase= ",up)
OUTPUT

The given file

2|P a ge
3. Remove all the lines that contain the character “a” in a file
and write it to another file
fp=open("sample text.txt","r")
lines=fp.readlines()
fp.close()
fp1=open("first.txt","w")
fp2=open("second.txt","w")
for line in lines:
if 'a' in line or 'A' in line:
fp2.write(line)
else:
fp1.write(line)
fp1.close()
fp2.close()
The given sample file

The first document

The second document

3|P a ge
4.(i) Create a binary file with a name and roll number search for a
given roll number and display the appropriate message(list)
import pickle
fp=open("student.dat","wb")
l=[ ]
while True:
rollno=int(input("enter the roll no"))
name=input("enter the name")
data=[rollno,name]
l.append(data)
pickle.dump(l,fp)
ch=input("enter Y for more records OR enter N or n for exit")
if ch in "Nn":
break
fp.close()
fp=open("student.dat","rb")
flag=0
try:
sno=int(input("enter the roll no to search"))
while True:
data=pickle.load(fp)
for i in data:
if i[0] == sno:
print("the name is ",i[1])
flag=1
break
except EOFError:
fp.close()
if (flag == 0):
print("nothing found")

4|P a ge
(ii) Create a binary file with a name and roll number search for a
given roll number and display the appropriate message(dictionary)
import pickle
fp=open("student.dat","wb")
d={ }
while True:
r=int(input("enter the roll no"))
n=input("enter the name")
d['roll']=r
d['name']=n
pickle.dump(d,fp)
ch=input("enter Y for more records OR enter N or n for exit")
if ch in "Nn":
break
fp.close()
fp=open("student.dat","rb")
flag=0

try:
sno=int(input("enter the roll no to search"))
while True:
data=pickle.load(fp)
if data['roll'] == sno:
print("the name is ",data['name'])
flag=1
break
except EOFError:
fp.close()
if (flag == 0):
print("nothing found")

5|P a ge
OUTPUT for the above code (both list and dictionary)

The exception performed

6|P a ge
5. (i) Create a binary file with a name and roll number search for a given
roll number and marks and input a roll number and update the marks
(list format)
import pickle
l=[ ]
fp=open("updatemarks.dat","wb")
while True:
r=int(input("Enter the roll no"))
n=input("Enter the name")
m=int(input("Enter the marks"))
data=[r,n,m]
l.append(data)
pickle.dump(l,fp)
ch=input("enter Y for more records OR enter N or n for exit")
if ch in "Vn":
break
fp.close()
fp=open("updatemarks.dat","rb")
f=0
try:
sno=int(input("Enter the Roll no to be searched"))
while True:
data=pickle.load(fp)
for i in data:
if i[0]==sno:
sm=int(input("Enter the new marks"))
i[2]=sm
print ("the updatedmarks",i)
f=1
break
except EOFError:
if(f==0):
print("Record is not found")

7|P a ge
(ii) Create a binary file with a name and roll number search for
a given roll number and marks and input a roll number and
update the marks(dictionary format)
import pickle
d={}
fp=open("updatemarks.dat","wb")
while True:
r=int(input("enter the roll number"))
n=input("enter the name")
m=int(input("enter the marks"))
d['roll']=r
d['name']=n
d['marks']=m
pickle.dump(d,fp)
ch=input("enter Y for more records OR enter N or n for exit")
if ch in 'Nn':
break
fp.close()
fp=open("updatemarks.dat","rb")
f=0
try:
sno=int(input("enter the roll no to search"))
while True:
data=pickle.load(fp)
if data['roll']==sno:
sm=int(input("enter marks new"))
data['marks']=sm
print(d,"update marks")
f=1
break

8|P a ge
except EOFError:
fp.close
if (f==0):
Print("record not found")

OUTPUT of the above code (both list and dictionary)

The exception performed

9|P a ge
6. Write a random number generator that generates
random numbers between 1 and 6 and stimulates a dice

import random
print("============ROLLING DICE ================")
while True:
num=random.randint(1,6)
if num == 6:
print("CONGRATS YOU GOT =",num)
else:
print("you have got",num)
ch=input("once again roll dice ")
if ch in 'Nn':
break

OUTPUT for the given code

10 | P a g e
7. Write a python program to implement stack using list
stack = []

def push():
value = int(input("Enter an element: "))
stack.append(value)

def pop():
if len(stack) == 0:
print("Stack is empty")
else:
a = stack.pop()
print("The removed element is", a)

def peek():
if len(stack) == 0:
print("Stack is empty")
else:
index = len(stack) - 1
print("The last element is", stack[index])

def display():
if len(stack) == 0:
print("Stack is empty")
else:
for i in stack:
print(i)

while True:
op = int(input("Press 1 for push, 2 for pop, 3 for peek, 4 for display, 5 for exit: "))

11 | P a g e
if op == 1:
push()
elif op == 2:
pop()
elif op == 3:
peek()
elif op == 4:
display()
elif op == 5:
break
else:
print("Invalid option. Please try again.")

OUTPUT for the above code

12 | P a g e
8. Create a csv file by entering user id and password ,read
and search the password for the given user id

import csv
with open("password.csv", "w", newline='') as fp:
w = csv.writer(fp)
w.writerow(["used Id", "password"])
while True:
username = input("Enter the username: ")
password = input("Enter the password: ")
w.writerow([username, password])
ch = input("Press 'y' for more records or 'n' to exit: ")
if ch.lower() == 'n':
break
f=0
with open("password.csv", "r") as fp:
vid = input("Enter username to search: ")
reader = csv.reader(fp)
next(reader)
for row in reader:
if row[0] == vid:
print("The given password is", row[1])
f=1
break
if f == 0:
print("Record not found")

13 | P a g e
OUTPUT for the given code

The given error performed

14 | P a g e
9. Prime number code
start=int(input("enter the start value"))
end=int(input("enter the end value"))
for i in range(start,end+1):
flag=0
if i == 1:
continue
for j in range(2,i):
if i%j == 0:
flag=1
break
if flag == 0:
print(i,"is prime number")

OUTPUT for the given code

15 | P a g e
10. Fibonacci code
n=int(input("upto how many terms"))
a,b=0,1
count=0
if n<=0:
print("Error! enter positive number")
elif n == 1:
print("fibonacci series upto",n,".")
print(a)
else:
print("fibbonacci series ")
while count<n:
print(a,end=' ')
c=a+b
a=b
a=c
count+=1
OUTPUT

The error performed

16 | P a g e
11. Armstrong number
n = int(input("Enter the number: "))
temp = n
arm = 0
while n > 0:
d = n % 10
arm += d ** 3
n //= 10
if arm == temp:
print("The number is an Armstrong number.")
else:
print("The number is not an Armstrong number.")

OUTPUT

17 | P a g e
12. Arithmetic operations
print("=======Arithmetic operations======")
def add():
a=int(input("enter first value="))
b=int(input("enter the second value="))
c=a+b
print("the addition of the given two numbers",c)
def sub():
a=int(input("enter first value="))
b=int(input("enter the second value="))
c=a-b
print("the subtracion of the given two numbers",c)
def mul():
a=int(input("enter first value="))
b=int(input("enter the second value="))
c=a*b
print("the multiplication of the given two numbers",c)
def div():
a=int(input("enter first value="))
b=int(input("enter the second value="))
try:
c=a/b
print("the divisions of the given two number=",c)
except:
print("please dont enter zero as a denominator value")

18 | P a g e
while True:
op=int(input("press 1 for addition,press 2 for subtraction,press 3 for
multiplication,4 for division,5 for exit"))
if op == 1:
add()
elif op == 2:
sub()
elif op == 3:
mul()
elif op == 4:
div()
elif op == 5:
break
else :
print("please enter valid option")
OUTPUT

19 | P a g e
13. List program
list1=[]
n=int(input("Enter the range:"))
for i in range(n):
element=int(input("Enter the element:"))
list1.append(element)
print("The given list is:",list1)
k=int(input("Enter the element to be searched:"))
for i in list1:
flag=0
if i==k:
flag=1
break
if flag==1:
print("Element is found")
else:
print("Element is not found")

OUTPUT

20 | P a g e
14. List program (swapping using list)

list1=[]
n=int(input("Enter the range:"))
for i in range(n):
element=int(input("Enter the element:"))
list1.append(element)
print("The given list before swapping is:",list1)
for i in range(0,len(list1)-1,2):
list1[i],list1[i+1]=list1[i+1],list1[i]

print("After Swapping the list is:",list1)

OUTPUT

21 | P a g e
15. Dictionary program
dict1={}
n=int(input("enter the range"))
for i in range(n):
Rollno=int(input("Enter the roll number"))
Name=input("Enter the name")
Marks=int(input("Enter the marks"))
dict1[Rollno]=[Name,Marks]
print("The Given Dictionary is",dict1)
for i in dict1:
if dict[i][1]>75:
print("The Name of the student who score more than 75 marks
is:",dict1[i][0])

OUTPUT

22 | P a g e
MySQL connectivity programs
16. creating a python program to integrate MySQL with python
(creating database and table )
import mysql.connector
def Create_DB():
Con=mysql.connector.connect(host="localhost",user="root",password="deeksha2024")

try:
if Con.is_connected():
cur=Con.cursor()
Q='create database employee'
cur.execute(Q)
print("employee database created successfully")
except:
print("database name already exists")
Con.close()
def Create_Table():
Con=mysql.connector.connect(host="localhost",user="root",password="deeksha2024")

try:
if Con.is_connected():
cur=Con.cursor()
Q="use employee"
cur.execute(Q)
Q="create table Emp(ENO integer primary key,ENAME varchar(20),GENDER varchar(5),SAL integer)"

cur.execute(Q)
print("emp table create successfully")
except:
print("Table name is already exists")
Con.close()

23 | P a g e
ch='y'
while ch=='y' or ch=='Y':
print("\nInterfacing Python with Mysql")
print("1. To create Database")
print("2.To create Table")
print("3.For exits")
opt=int(input("enter your choice:"))
if opt==1:
Create_DB()
elif opt==2:
Create_Table()
else:
break

OUTPUT

24 | P a g e
17.To write a python program to integrate MySQL with python
by inserting records to EMp table and display the records
import mysql.connector
con=mysql.connector.connect(host='localhost',username='root',password=“deeksha2024”,database='employee')

try:
if con.is_connected():
cur=con.cursor()
opt='y'
while opt=='y':
No=int(input("Enter Employee number"))
Name=input("Enter Employee name")
Gender=input("Enter Employee gender(M/F):")
Salary=int(input("Enter Employee Salary:"))
Query="insert into Emp values({},'{}','{}',{})".format(No,Name,Gender,Salary)

cur.execute(Query)
con.commit()
print("Record stored successfully")
opt=input("Do you want to add another employee details(y/N):")
except:
print("Records already exists")

Query="select *from Emp"


cur.execute(Query)
data=cur.fetchall()
for i in data:
print(i)
con.close()

25 | P a g e
OUTPUT

26 | P a g e
18. Creating a python program to integrate MySQL with python
(searching and displaying the records)
import mysql.connector
con=mysql.connector.connect(host='localhost',username='root',password=“deeksha2024”,database='employee')

if con.is_connected():
cur=con.cursor()
print("*******************************")
print("Welcome Employee Search Screen")
print("*******************************")
No=int(input("Enter the employee number to search:"))
Query='select *from emp where Empid={}'.format(No)
cur.execute(Query)
data=cur.fetchone()
if data!=None:
print(data)
else:
print("Record not found")
con.close()

OUTPUT

27 | P a g e
19.Creating python program to integrate MySQL with python
(updating records)

import mysql.connector
con=mysql.connector.connect(host='localhost',username='root',password=’deeksha2024’,database='employee' )
if con.is_connected():
cur=con.cursor()
print("****************************************************")
print("Welcome to Employee detail update screen")
print("****************************************************")
No=int(input("Enter Employee number to update"))
Query="Select *from Emp where empid={}".format(No)
cur.execute(Query)
data=cur.fetchone()
if data!=None:
print("Record found details are")
print(data)
ans=input("DO you want to update the salary of the employee(y/n):")
if ans=='y' or ans=='Y':
New_sal=int(input("Enter new salary of the employee"))
Q1="update Emp set sal={} where empid={}".format(New_sal,No)
cur.execute(Q1)
con.commit()
print("Employee Salary updated successsfully")
Q2='select *from Emp'
cur.execute(Q2)
data=cur.fetchall()
for i in data:
print(i)
else:
print("Record is not found")

28 | P a g e
OUTPUT

29 | P a g e
SQL PROGRAMES
20. To write Queries for the following Questions based on the given table.
AIM:

Rollno Name Gender Age Dep DOA Fees


1 Ankit M 21 COMPUTER 1997-01-10 120
2 Bala M 22 HISTORY 1998-03-24 200
3 Deepa F 24 HINDI 1996-12-12 500
4 Dinesh M 21 NULL 1999-07-01 250
5 Usha F 20 HISTORY 1997-02-25 150
6 Charan M 19 COMPUTER 1997-06-25 210

a) Write a Query to Create a new database in the name of “STUDENTS”.

CREATE DATABASE STUDENTS;

b) Write a Query to open the database “STUDENTS”.

USE STUDENTS;

c) Write a Query to create the above table called:”STU”.

CREATE TABLE STU(ROLLNO INT PRIMARY KEY, NAME VARCHAR(10),


GENDER VARCHAR(10),AGE INT,DEP VARCHAR(10),
DOA DATE,FEES INT);

d) Write a Query to list all existing database names

SHOW DATABASES;

30 | P a g e
e) Write a Query to List all the tables that exists in the current database.

SHOW TABLES;

31 | P a g e
21. To write Queries for the following Questions based on the given table.
AIM

Rollno Name Gender Age Dep DOA Fees


1 Ankit M 21 COMPUTER 1997-01-10 120
2 Bala M 22 HISTORY 1998-03-24 200
3 Deepa F 24 HINDI 1996-12-12 500
4 Dinesh M 21 NULL 1999-07-01 250
5 Usha F 20 HISTORY 1997-02-25 150
6 Charan M 19 COMPUTER 1997-06-25 210

a) Write a Query to insert all the rows of above table into Info table.

INSERT INTO STU VALUES (1,’ANKIT’,’M’,21,’COMPUTER’,’1997-01-10’,120);


INSERT INTO STU VALUES (2,’BALA’,’M’,22,’HISTORY,’1998-03-24’,200);
INSERT INTO STU VALUES (3,’CHARAN’,’M’,19,'COMPUTER,’1997-06-25’,210);
INSERT INTO STU VALUES (4,’DEEPA’,’F’,24,’HINDI’,’1996-12-12’,500);
INSERT INTO STU VALUES (5,’DINESH’,’M’,21,NULL,’1999-07-01’,250);
INSERT INTO STU VALUES (6,’USHA’,’F’,20,’HISTORY’,’1997-01-10’,150);

b) Write a Query to display all the details of the Student from the table “STU”.

SELECT *FROM STU;

c) Write a Query to Rollno,Name,and Department of the student from table ”STU”.

SELECT ROLLNO,NAME,DEP FROM STU;

32 | P a g e
d) Write a Query to select distinct Department from STU table.

SELECT DISTINCT(DEP) FROM STU;

e) To show all information about students of HISTORY department.

SELECT *FROM STU WHERE DEP=’HISTORY’;

33 | P a g e
22. To write Queries for the following Questions based on the given table.
AIM:

Rollno Name Gender Age Dep DOA Fees


1 Ankit M 21 COMPUTER 1997-01-10 120
2 Bala M 22 HISTORY 1998-03-24 200
3 Deepa F 24 HINDI 1996-12-12 500
4 Dinesh M 21 NULL 1999-07-01 250
5 Usha F 20 HISTORY 1997-02-25 150
6 Charan M 19 COMPUTER 1997-06-25 210

a) Write a Query to list name of female students in Hindi Department.

SELECT NAME FROM STU WHERE DEP=’HINDI’ AND GENDER=’F’;

b) Write a Query to List name of the student whose age are between 18 to 20.

SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;

c) Write a Query to display the name of the students whose name starts with “A”.

SELECT NAME FROM STU WHERE NAME LIKE ‘A%’;

34 | P a g e
d) Write a Query to list the names of those students whose name have second alphabet
‘n’ in their names.

SELECT NAME FROM STU WHERE NAME LIKE ‘_N%’;

35 | P a g e
23. To write Queries for the following Questions based on the given table.
AIM:

Rollno Name Gender Age Dep DOA Fees


1 Ankit M 21 COMPUTER 1997-01-10 120
2 Bala M 22 HISTORY 1998-03-24 200
3 Deepa F 24 HINDI 1996-12-12 500
4 Dinesh M 21 NULL 1999-07-01 250
5 Usha F 20 HISTORY 1997-02-25 150
6 Charan M 19 COMPUTER 1997-06-25 210
a) Write a Query to delete the details of Roll Number is 6.

DELETE FROM STU WHERE ROLLNO=6;

b) Write a Query to change the fees of a student to 170 whose Roll Number is 1,if the
existing fees is less than 130.

UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND FEES<130;

c) Write a Query to add new column AREA of type varchar in table “STU”.

ALTER TABLE STU ADD AREA VARCHAR(10);

d) Write a Query to Display Name of all students Area Constraints Null.

SELECT NAME FROM STU WHERE AREA IS NULL;

36 | P a g e
e) Write a Query to delete Area column from the table STU.

ALTER TABLE STU DROP COLUMN AREA;

a) Write a Query to delete the table from database.

DROP TABLE STU;

37 | P a g e
AIM:-24
To write Queries for the following Questions based on the given table.
TABLE:UNIFORM

Ucode Uname Ucolor StockDate


1 Shirt White 2021-03-31
2 Pant Black 2020-01-01
3 T-shirts Grey 2021-02-18
4 Tie Blue 2019-01-01
5 Socks Blue 2019-03-19
6 Belt Black 2017-12-09

TABLE:COST

Ucode Size Price Company


1 M 500 Rayomd
1 L 580 Mattex
2 XL 620 Mattex
2 M 810 Yasin
2 L 940 Raymond
3 M 770 Yasin
3 L 830 Galin
4 S 150 Mattex

a) To Display the average price of all the Uniform of Raymond Company from table
Cost.

SELECT AVG(PRICE) FROM COST WHERE COMPANY=’RAYMOND’;

b) To display details of all the Uniform table in descending order of Stock date.

SELECT *FROM UNIFORM ORDER BY STOCKDATE DESC;

38 | P a g e
c) To display max price and min price of each company

SELECT COMPANY,MAX(PRICE),MIN(PRICE) FROM COST GROUP BY


COMPANY;

d)To display the company were the number of uniform size is more than 2

select company,count(*)from cost group by company having


count(*)>2;

39 | P a g e
e)to display ucode ,uname,ucolor,size and company of tables uniform and cost
select u.ucode,uname,ucolor,size,company from uniform u,cost c
where u.ucode=c.ucode;

40 | P a g e

You might also like