[go: up one dir, main page]

0% found this document useful (0 votes)
25 views48 pages

Practical

The document provides the details of a practical file submission for the subject Computer Science by the student Pulkit Tanwar of class 12. It includes a certificate signed by the internal and external examiners and principal. The index lists 35 programs written by the student on various topics like functions, file handling, database, SQL queries etc. along with their outputs.

Uploaded by

Pulkit Tanwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views48 pages

Practical

The document provides the details of a practical file submission for the subject Computer Science by the student Pulkit Tanwar of class 12. It includes a certificate signed by the internal and external examiners and principal. The index lists 35 programs written by the student on various topics like functions, file handling, database, SQL queries etc. along with their outputs.

Uploaded by

Pulkit Tanwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

The Navyandhra School

Computer Science (083)

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;

18 Write a query to select student name which starts from ‘k’.

19 Use of Order by command


i. Write a sql query to order marks of students in ascending order.
ii. Write a sql query to order marks of students in descending order.
20 Use concat function in mysql record to concat field names and show records in
both fields.
21 Use Trim function to remove spaces from left and right of the field name and
record.
22 Use Upper and Lower function in mysql to get field name in upper and lower
case.
23 Use Ucase and Lcase to get record and fields in upper and lower case.
24 Write a query using Between and not between Function between two fields in
mysql.
25 Write a query to delete record based on a condition of class=”X”
26 Write a query to select distinct class from stu_det.
27 Use group by command to select count(rno)and class from stu_det table.
28 Use Min,Max,Avg functions to retrieve minimum,maximum,average marks from
stu_det table.
29 Create table orders and execute following commands-
Alter, Update, Delete or drop column.
30 Use Join command on employee and department table.
31 Write SQL commands on the basis of table STUDENT:
i. To display name and average marks of all the students having
AVGMARK<70.0
ii. To display list of all the students with stipend > 350.00 in ascending order
of name
iii. List all the students sorted by AVGMARK in descending order.
iv. Select the names of the students who are in class XII sorted by stipend.
v. To count the number of students with Grade=’A’
vi. To insert a new student in the table as follows:
vii. ‘5’, ’Radha’, 500.00,” COMMERCE”, 90.8, ’A’, ‘XII A’
viii. Update the student’s stipend with Rs100/- whose Grade is ‘A’.
ix. Display the unique stream names and grades from the student table.
x. Output of Select min(AVGMARK) from student
xi. Select sum (STIPEND) from student where grade=”b”.
xii. Select AVG(STIPEND) from student where class=”XII A
xiii. Select count(DISTINCT STREAM) from STUDENT;
xiv. Select Name of student ending with “a”.
32 WAP to implement a stack for the student details (rno, stname, marks).
33 Write a mysql connectivity program in Python to create a database school.
34 WAP to create a table student_school in the existing database school.
35 WAP to insert a record in the existing table school_student table using python
Mysql connectivity.

Write Python Program to find Diameter,Circumference and Area Of a


Circle using function with a practical example.
import math
def cal_Diameter(radius):
return 2 * radius
def cal_Circum(radius):
return 2 * math.pi * radius
def cal_Area(radius):
return math.pi * radius * radius
r = float(input("Enter the radius of a circle: "))
diameter = cal_Diameter(r)
circumference = cal_Circum(r)
area = cal_Area(r)
print("Diameter Of a Circle = %.2f" %diameter)
print("Circumference Of a Circle = %.2f" %circumference)
print("Area Of a Circle = %.2f" %area)

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

Write a python program to perform the basic arithmetic operations in a menu-driven


program with different functions. The output should be like this:
Select an operator to perform the task:
‘+’ for Addition
‘-‘ for Subtraction
‘*’ for Multiplication
‘/’ for Division

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):

st_name=input("Enter student name:")

r=int(input("Enter your Roll Number:"))

m=int(input("Enter your Marks:")) l.append(str(r)+"\t"+st_name+"\


t"+str(m)+"\n")

print(l)

f.writelines(l)

f.close()

OUTPUT

Enter student name:Rahul

Enter your Roll Number:12

Enter your Marks:32


Enter student name:Sarthak
Enter your Roll Number:23
Enter your Marks:78
Enter student name:Vihan
Enter your Roll Number:4
Enter your Marks:24
['12\tRahul \t32\n', '23\tSarthak\t78\n', '4\tVihan\t24\n']

WAP to count the number of record present in student.csv file.


import csv

with open("C:\\ Users\\narayana\\Desktop\\Student.csv")as f:

csv_reader=csv.reader(f)
row=[]

for rec in csv_reader:

if csv_reader.line_num==0:

continue
row.append(rec)
value=len(list(csv_reader))
print(row)
print(value)

OUTPUT

WAP to search and print the record of specific file


import csv

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

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:

Whose woods these are I think I


know His house is in the village
though;
He will not see me stopping here
To watch his woods, fill up with snow

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

My first book was Me


and My Family. It
gave me
chance to
be Known
to the world.

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:

Whose woods these are I think I


know His house is in the village
though;
He will not see me stopping here
To watch his woods, fill up with snow

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 create a Database Student1:


mysql> create database student1;

To Show Database:
mysql> show databases;

To use a Database:
mysql> use student1;

To create a table in Database:


mysql> create table stu_det(rno integer,s_name varchar(25), class
varchar(10), marks decimal(4,2));
To Show tables in Database:
mysql> show tables;

To see content of Database:


mysql> desc stu_det;

To insert Data in Tables:


mysql> insert into stu_det values(101,"Sarthak","X",99.5); mysql> insert into
stu_det values(102,"Rahul","X",89);
mysql>insert into stu_det values(103,"Avni","XI",85);
mysql>insert into stu_det values(104,"Dheeraj","XI",95);
mysql>insert into stu_det values(105,'Kirtiman','X',85)
mysql> insert into stu_det values(106,"Deepshikha","XII",89);

To Show data in Database:


mysql> select * from stu_det;
To Select Particular Field from Table:
mysql> select rno,marks from stu_det;

To Select a row based on condition:


mysql> select * from stu_det where marks>=90;

To Update a record in a table;


mysql> update stu_det set marks=99 where rno=102;
mysql> select * from stu_det;

mysql> update stu_det set marks=85 where s_name="Dheeraj";

mysql> select * from stu_det;


Use of logical operators And and OR:
mysql> select rno,s_name,marks from stu_det where rno=101 and marks>90;
Output:

 (&&) is used for ‘and’ operator and (||) is used for OR operator:

mysql> select rno,s_name,marks from stu_det where rno=101 && marks>90;

mysql> select rno,s_name,marks from stu_det where rno=103 || marks>90;


mysql> select * from stu_det where marks between 80 and 100;

mysql> select * from stu_det where marks>=90 and marks<=100;

mysql> select * from stu_det where class='XII' or class='X';


mysql> select * from stu_det where s_name like "k%";

Ordering Data:

Order Command:
mysql> select * from stu_det order by marks;

mysql> select * from stu_det order by marks desc;


Functions in MySQL:
Concat():
mysql> select concat("Rahul","Yadav");

mysql> select concat(rno," ",s_name) as "Roll and Name" from stu_det;

Trim():
mysql> select rtrim("Hello World");

mysql> select ltrim("Bye World");


mysql> select trim("Hello Me ");

Upper():
mysql> select upper("hello");

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():

mysql> select round(15.35678,2);

Sqrt():
mysql> select sqrt(7);

Curdate ()
mysql> select curdate();
Between():

mysql> select * from stu_det where marks between 90 and 100;

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;

Mysql>select avg(marks) from stu_det;


mysql> select max(marks) from stu_det;

mysql> select min(marks) from stu_det;

Q.Create table orders and execute following operations-


Alter, Update, Delete or drop column.

mysql>create table orders(order_no int ,order_date date,Qty int,ItemNo int,city


varchar(50),price int,feedback varchar(200));

mysql> insert into orders values(1001,"2022-06-19",6,10,"Bhopal",30000,"Good");

mysql> insert into orders values(1002,"2022-06-19",4,10,"Delhi",20000,"Average");


Syntax:

mysql> alter table <tablename> add <field-name> <datatype>;


For eg:
mysql> alter table orders add payment varchar(30);

mysql> desc orders;

To Delete or Drop a column in table;


Syntax;
mysql> alter table table_name drop column column_name;
mysql> alter table orders drop column price;
Update Statement;
mysql> update orders set city="Gwalior" where ord_no=1002

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");

mysql>>SELECT employees.employee_id, department.department FROM employees,


department where employees.department_id = department. department_id;
Q. Write SQL commands on the basis of table STUDENT:

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;

Q3. List all the students sorted by AVGMARK in descending order.


mysql> select * from STUDENT order by AVGMARK desc;

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";

Q6. To insert a new student in the table as follows:


‘5’, ’Radha’, 500.00,” COMMERCE”, 90.8, ’A’, ‘XII 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;

Q10. Output of Select min(AVGMARK) from student

Q11. Select sum (STIPEND) from student where grade=”b”.

Q12. Select AVG(STIPEND) from student where ClASS=”XII A”;


Q13. Select count(DISTINCT STREAM) from STUDENT;

Q14. Select Name of student ending with “a”.


WAP to implement a stack for the student details (rno, stname, marks).
student=[]
def push():
rno=input("Enter rollno ")
stuname=input("Enterstudentname")
marks=input("Enter marks ")
stud=(rno,stuname,marks)
student.append(stud)
def pop():
if(student==[]):
print("Underflow/studentStackinempty")
else:
rno,stuname,marks=student.pop()
print("poped element is ")
print("rno ",rno," stuname ",stuname," marks ",marks)
def dispstack():
if not (student==[]):
n=len(student)
for i in range(n-1,-1,-1):
print(student[i])
else:
print("Empty , No student to display")
while True:
print("1.Push")
print("2. Pop")
print("3. displaystack")
print("4. Exit")
ch=int(input("Enter your choice "))
if(ch==1):
push()
elif(ch==2):
pop()
elif(ch==3):
dispstack()
elif(ch==4):
print("End")
break

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:

if con is not None and con.is_connected():


con.close()
print("Connection closed")

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

You might also like