Practical
Practical
SUBMITTED BY SUBMITTED TO
Pulkit Tanwar Ms. Rekha Mishra
Roll No.-______ PGT Computer Science
Practical File
Computer Science
Class XII
Session 2023-2024
By: Pulkit Tanwar
CERTIFICATE
This is to certify that Pulkit Tanwar of Class XII Science has successfully
completed their Computer Science (083) Practical File.
___________________ ___________________
EXTERNAL EXAMINER INTERNAL EXAMINER
________________
PRINCIPAL
Index
Sr. No. Programs
1 Write python program to find diameter,circumference and area of a circle using
function with a practical example.
2 Write a python program to exchange the values of two numbers with practical
example
3 Write a python program to perform the basic arithmetic operations in a menu-
driven program with different functions.
4 Wap to print roll no, names, marks of all the students of a class and
store these details in a text file named marks.txt
5 Wap to count the number of record present in student.csv file.
6 Wap to search and print the record of specific file.
7 Wap to read a text file and display the count of vowels and consonants in that file
8 Write a function countmy() in python to read the text file “data.txt” and count the
number of times my occurs in the file.
9 Write a user-defined function counth() in python that displays the number of lines
starting with ‘h’ in the file “para.txt”.
10 Write a function in python that counts the number of “me” or “my” words present
in a text file “story.txt”.
11 Write a function countmy() in python to read the text file “data.txt” and count the
number of times my occurs in the file
12 Write a user-defined function counth() in python that displays the number of lines
starting with ‘h’ in the file “para.txt”.
13 Write a query To create a Database Student1 and execute following commands-
i. To Show Database
ii. To use a Database
iii. To create a table in Database
iv. To Show tables in Database
v. To see content of Database
vi. To insert Data in Tables
14 Write a query to select rno,marks from stu_det;
15 Write a query to select stu_det where marks>=90;
16 i.Write a query to update stu_det set marks=99 where rno=102;
ii. Write a query to update stu_det set marks=85 where s_name="Dheeraj";
17 Use of logical operators And and OR
i. Write a query to select rno,s_name,marks from stu_det where rno=101
and marks>90;
ii. Write a query to select rno,s_name,marks from stu_det where rno=101 &&
marks>90;
iii. Write a query to select rno,s_name,marks from stu_det where rno=103 ||
marks>90;
iv. Write a query to select from stu_det where marks between 80 and 100;
v. Write a query to select * from stu_det where marks>=90 and marks<=100;
OUTPUT
Write a Python Program to Exchange the Values of Two Numbers with Practical
Example
def swap(x, y):
temp = x
x=y
y = temp
print("After swapping")
print("Value of first number :", x)
print("Value of second number :", y)
num1 = int(input("Enter first number :"))
num2 = int(input("Enter second number :"))
print("Before swapping")
print("Value of first number :",num1)
print("Value of second number :",num2)
swap(num1,num2)
OUTPUT
def main():
print('+ for Addition')
print('- for Subtraction')
print('* for Multiplication')
print('/ for Division')
ch = input("Enter your choice:")
if ch=='+':
x=int(input("Enter value of a:"))
y=int(input("Enter value of b:"))
print("Addition:",add(x,y))
elif ch=='-':
x=int(input("Enter value of a:"))
y=int(input("Enter value of b:"))
print("Subtraction:",sub(x,y))
elif ch=='*':
x=int(input("Enter value of a:"))
y=int(input("Enter value of b:"))
print("Multiplication",mul(x,y))
elif ch=='/':
x=int(input("Enter value of a:"))
y=int(input("Enter value of b:"))
print("Division",div(x,y))
else:
print("Invalid character")
def add(a,b):
return a+b
def sub(a,b):
return a-b
def mul(a,b):
return a*b
def div(a,b):
return a/b
main()
OUTPUT
WAP to print Roll No , Names ,Marks of all the students of a class and
store these details in a text file named Marks.txt
f=open("Marks.txt","a") l=[]
for i in range (3):
print(l)
f.writelines(l)
f.close()
OUTPUT
csv_reader=csv.reader(f)
row=[]
if csv_reader.line_num==0:
continue
row.append(rec)
value=len(list(csv_reader))
print(row)
print(value)
OUTPUT
with open("C:\\Users\\narayana\\Desktop\\Student.csv") as f:
csv_reader=csv.reader(f)
n=input("Enter the name of record:")
for i in csv_reader:
if i[1]==n:
print(i)
OUTPUT
WAP to read a text file and display the count of Vowels and consonants in that file
f=open("C:\\Users\\narayana\\Desktop\\vowcon.txt","r")
c=0
v=0
s1=f.read()
l=len(s1)
print(l)
for i in range(l):
if s1[i].isalpha():
if s1[i] in ("a","e","i","o","u","A","E","I","O","U"):
v=v+1
else:
c=c+1
print("Number of vowels:",v)
print("Number of consosnants:",c)
OUTPUT
Write a function countmy() in python to read the text file “Data.txt” and
count the number of times my occurs in the file.
def countmy():
fp=open("C:\\Users\\narayana\\Desktop\\Data.txt","r")
st=fp.read()
lst=st.split(" ")
l=len(lst)
print(lst)
c=0
for i in range(l):
if lst[i] in ("my","My"):
c=c+1
return c
z=countmy()
print("my occurs",z,"times")
OUTPUT
def countH(a):
c=0
for i in range(l):
if a[i][0] in ("H","h"):
c=c+1
return c
fp=open("C:\\Users\\narayana\\Desktop\\Para.txt","r")
st=fp.readlines()
l=len(st)
x=countH(st)
print("Number of H is:",x)
OUTPUT
Write a function in Python that counts the number of “Me” or “My” words
present in a text file “STORY.TXT”. If the “STORY.TXT” contents are as follow
def countme_my():
fp=open("C:\\Users\\narayana\\Desktop\\story1.txt","r")
st=" "
c=0
v=0
while st:
st=fp.readline()
lst=st.split(" ")
print(lst)
l=len(lst)
for i in range(l):
if lst[i] in ("Me","me\n","me"):
c=c+1
if lst[i] in ("My","my\n","me"):
v=v+1
return (c+v)
z=countme_my()
print("Count of Me/My in file:",z)
OUTPUT
WAP to read a text file and display the count of Vowels and consonants in that file
f=open("C:\\Users\\narayana\\Desktop\\vowcon.txt","r")
c=0
v=0
s1=f.read()
l=len(s1)
print(l)
for i in range(l):
if s1[i].isalpha():
if s1[i] in ("a","e","i","o","u","A","E","I","O","U"):
v=v+1
else:
c=c+1
print("Number of vowels:",v)
print("Number of consosnants:",c)
OUTPUT
Write a function countmy() in python to read the text file “Data.txt” and
count the number of times my occurs in the file.
def countmy():
fp=open("C:\\Users\\narayana\\Desktop\\Data.txt","r")
st=fp.read()
lst=st.split(" ")
l=len(lst) print(lst)
c=0
for i in range(l):
if lst[i] in ("my","My"):
c=c+1
return c
z=countmy()
print("my occurs",z,"times")
OUTPUT
Write a user-defined function countH() in python that displays the
number of lines starting with ‘H’ in the file “Para.txt”. Example, if the file
contains:
def countH(a):
c=0
for i in range(l):
if a[i][0] in ("H","h"):
c=c+1
return c
fp=open("C:\\Users\\narayana\\Desktop\\Para.txt","r")
st=fp.readlines()
l=len(st)
x=countH(st)
print("Number of H is:",x)
OUTPUT
RELATIONAL DATABASE
To Show Database:
mysql> show databases;
To use a Database:
mysql> use student1;
(&&) is used for ‘and’ operator and (||) is used for OR operator:
Ordering Data:
Order Command:
mysql> select * from stu_det order by marks;
Trim():
mysql> select rtrim("Hello World");
Upper():
mysql> select upper("hello");
Lower():
mysql> select lower("HELLO");
mysql> select lower("hello");
Ucase():
mysql> select ucase("hello how are you");
Lcase():
mysql> select lcase("HELLO I AM GOOD");
Substr() :
mysql> select substr("This is my book,",3,4);
Length():
mysql> select length("Hello how are you doing");
Round():
Sqrt():
mysql> select sqrt(7);
Curdate ()
mysql> select curdate();
Between():
Not Between():
mysql> select * from stu_det where marks not between 90 and 100;
Delete():
mysql> delete from stu_det where class="X";
Distinct
mysql> select distinct class from stu_det;
Group By:
Mysql>select count(rno),class from stu_det group by class;
Join Command
create table employees(employee_id varchar(20),Department id varchar(20));
mysql> create table employees(employee_id varchar(20),Department_id); varchar(20));
mysql> insert into employees values("E101","D101");
mysql> insert into employees values("E102","D102");
mysql> insert into employees values("E103","D103");
mysql> insert into employees values("E104","D104");
mysql> insert into employees values("E105","D105");
create table department(department_id varchar(20),Department varchar(40));
insert into department values("D101","Marketing");
mysql> insert into department values("D102","Sales");
mysql> insert into department values("D103","IT");
mysql> insert into department values("D104","Administration");
insert into department values("D105","HR");
Code:
mysql> create table student( RNO varchar(1) PRIMARY KEY NOT NULL,NAME varchar(10),STIPEND
float(10),STREAM varchar(10),AVGMARK float(10),GRADE varchar(10),CLASS varchar(10));
Q1. To display name and average marks of all the students having AVGMARK<70.0
mysql> select * from STUDENT where AVGMARK<70.0;
Q2. To display list of all the students with stipend > 350.00 in ascending order of name
mysql> select * from STUDENT where STIPEND>350.0 order by NAME
asc;
Q4. Select the names of the students who are in class XII sorted by
stipend mysql> select * from STUDENT order by STIPEND;
Q5. To count the number of students with Grade=’A’
mysql> select GRADE,count(*) from STUDENT where GRADE="A";
Q7. Update the student’s stipend with Rs100/- whose Grade is ‘A’.4
mysql> update STUDENT set STIPEND=100 where GRADE='A'; Query
OK, 2 rows affected (0.02 sec)
Rows matched: 2 Changed: 2 Warnings: 0 mysql>
select * from STUDENT;
Q9. Display the unique stream names and grades from the student
table.
mysql> select DISTINCT STREAM,GRADE from STUDENT;
else:
print("Invalid choice")
OUTPUT
Write a MySQL connectivity program in Python to create a database school.
import mysql.connector as c
from mysql.connector import Error con=None
try:
con=c.connect(host='localhost', user='root', passwd="123456")
if con.is_connected():
print("successfullyconnected")
db=con.cursor()
q1="createdatabaseschool;"
db.execute(q1)
print("school database created")
con.close()
except Error as e:
print(e)
finally:
if con is not None and con.is_connected():
con.close()
print("Connection closed")
OUTPUT
WAP to create a table student_school in the existing database school.
import mysql.connector as c
from mysql.connector import Error con=None
try:
con=c.connect(host='localhost',user='root',
passwd="123456",database="school")
if con.is_connected():
print("successfully connected")
mycursor=con.cursor()
q1="create table student_school( rollno int, name char(15), M1
float, M2 float, M3 float, M4 float, M5 float, total float, per
float);"
mycursor.execute(q1)
print("student table created")
except Error as e:
print(e)
finally:
OUTPUT
WAP to insert a record in the existing table school_student table using python Mysql
connectivity.
import mysql.connector as c
from mysql.connector import Error con=None
try:
con=c.connect(host='localhost',user='root',
passwd="123456",database="school")
if con.is_connected():
print("successfullyconnected")
db=con.cursor()
r='1'
n='ArnavSharma'
m11='80'
m12='70'
m13='75'
m14='66'
m15='88'
db.execute("insertintostudent_school
(rollno,name,M1,M2,M3,M4,M5) values
(%s,%s,%s,%s,%s,%s,%s)",(r,n,m11,m12,m13,m14,m15))
#to save the data
con.commit()
print("Record Saved: 1 Record Inserted")
except Error as e:
print(e)
finally:
if con is not None and con.is_connected():
con.close()
print("Connection closed")
OUTPUT