0% found this document useful (0 votes)
14 views

Untitled Document

Uploaded by

imshayan24jan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Untitled Document

Uploaded by

imshayan24jan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

CERTIFICATE

This is to certify that candidate SHAYAN SHARIQ


ROLL NO: 14617313 has successfully completed
the Practical Work in the subject Computer
Science (083) laid down in the regulations of CBSE
for the purpose of Practical Examination in Class
XII to be held in ST MARKS SR SEC PUBLIC
SCHOOL, DELHI on ______________.

Internal Examiner External Examiner

Principal
ACKNOWLEDGEMENT
We are overwhelmed in all humbleness and
gratefulness to acknowledge our depth to all
those who have helped us to put these ideas
well above the level of simplicity and into
something concrete.

We are very thankful to our guide and teacher


for his valuable help. He was always there to
show us the right track when we needed his
help. With the help of his valuable suggestions,
guidance and encouragement, we were able to
perform this project work.

We would also like to thank our Principal


MRS SUMAN SINGH, who often helped and
gave us support to carry out this project
successfully
PROGRAM - 1
(Python)
AIM: Write a python program to take input for 2 numbers and an
operator (+ , – , * , / ). Based on the operator calculate and print the
result?

SOURCE CODE

OUTPUT
PROGRAM - 2
AIM: Write a python program using a function to print factorial number
series from n to m numbers.

SOURCE CODE

OUTPUT
PROGRAM - 3
AIM: Write a python program to accept username "SHAYAN" as default
argument and password “HELLO” entered by user to allow login into the
system.

SOURCE CODE

OUTPUT
PROGRAM - 4
AIM: Write a python program to calculate product and power of the first 10
numbers.

SOURCE CODE

OUTPUT
PROGRAM - 5
AIM: Read a text file and display the number of vowels/ consonants/ uppercase/
lowercase characters and other than character and digit in the file.

SOURCE CODE
OUTPUT
PROGRAM - 6
AIM: Write a Python program to accept a list as a function parameter and raise the
IndexError exception.

SOURCE CODE

OUTPUT
PROGRAM - 7
AIM: Create a text file "shayan.txt" in python and ask the user to write a single line
text by user input.

SOURCE CODE

OUTPUT

PROGRAM - 8
PROGRAM - 8
AIM: Write a program to replace all spaces from text with - (dash) from the file
intro.txt.

SOURCE CODE

OUTPUT
PROGRAM - 9
AIM: Write a program to count a total number of lines and count the total number of
lines starting with 'A', 'B', and 'C' from the file intro.txt.

SOURCE CODE

OUTPUT
PROGRAM - 10
AIM: Create a binary file client.dat to hold records like ClientID, Client name, and
Address using the dictionary. Write functions to write data, read them, and print on
the screen.

SOURCE CODE

OUTPUT
PROGRAM - 11
AIM: Write a program to write data into binary file marks.dat and display the
records of students who scored more than 95 marks or less than 40 marks….

SOURCE CODE
OUTPUT
PROGRAM - 12
AIM: Read a CSV file shayan.csv and print the contents in a proper format. The
data for shayan.csv file are as following:

S/No Student Class Marks Gender

1 Shayan 12 - C 100 Male

2 kanan 12 - A 89 Female

3 Vidhi 12 - B 64 Female

4 Snehal 12 - D 89 Male

5 Labhesh 12 - E 25 Male

SOURCE CODE
OUTPUT
PROGRAM - 13
AIM: Read a CSV file top5.csv and print them with tab delimiter. Ignore the first row
header to print in tabular form.

SOURCE CODE

OUTPUT
PROGRAM - 14
AIM: Write a python program to check whether a string is a palindrome or not
using stack.

SOURCE CODE
OUTPUT
PROGRAM - 15
AIM: Write a python program to take input for 3 numbers, check and print the
largest number?

SOURCE CODE

OUTPUT
SQL Queries
16. Consider the following MOVIE table and write the SQL queries based
on it.
ReleaseDat ProductionCos BusinessCos
Movie_ID MovieName Type
e t t
M001 Dahek Action 2022/01/26 1245000 1300000
M002 Attack Action 2022/01/28 1120000 1250000
M003 Looop Lapeta Thriller 2022/02/01 250000 300000
M004 Badhai Do Drama 2022/02/04 720000 68000
Shabaash
M005 Biography 2022/02/04 1000000 800000
Mithu
M006 Gehraiyaan Romance 2022/02/11 150000 120000
a) Display all information from movie.
b) Display the type of movies.
c) Display movieid, moviename, total_eraning by showing the business
done by the movies. Claculate the business done by movie using the
sum of productioncost and businesscost.
d) Display movieid, moviename and productioncost for all movies with
productioncost greater thatn 150000 and less than 1000000.
e) Display the movie of type action and romance.
f) Display the list of movies which are going to release in February,
2022.
Answers:
a) select * from movie;
b) select distinct from a movie;

c) select movieid, moviename, productioncost + businesscost "total


earning" from movie;

d) select movie_id,moviename, productioncost from movie where


producst is >150000 and <1000000;

e) select moviename from movie where type ='action' or type='romance';


f) select moviename from movie where month(releasedate)=2;

17. Consider the given table patient and Write following queries:

a) Display the total charges of patient admitted in the month of


November.
b) Display the eldest patient with name and age.
c) Count the unique departments.
d) Display an average charges.
Answers:
a) select sum(charges) from patient
where dateofadm like '%-11-%';
b) select pname,max(age) from patient;

c) Select count(distinct department) from patient;

d) Select avg(charges) from patient;


18. Suppose your school management has decided to conduct cricket
matches between students of Class XI and Class XII. Students of each
class are asked to join any one of the four teams – Team Titan, Team
Rockers, Team Magnet and Team Hurricane. During summer
vacations, various matches will be conducted between these teams.
Help your sports teacher to do the following:
a) Create a database “Sports”.
b) Create a table “TEAM” with following considerations:
a. It should have a column TeamID for storing an integer value
between 1 to 9, which refers to unique identification of a team.
b. Each TeamID should have its associated name (TeamName),
which should be a string of length not less than 10 characters.
c. Using table level constraint, make TeamID as the primary key.
c) Show the structure of the table TEAM using a SQL statement.
d) As per the preferences of the students four teams were formed as given
below. Insert these four rows in TEAM table:
a. Row 1: (1, Tehlka)
b. Row 2: (2, Toofan)
c. Row 3: (3, Aandhi)
d. Row 3: (4, Shailab)
e) Show the contents of the table TEAM using a DML statement.
f) Now create another table MATCH_DETAILS and insert data as shown below.
Choose appropriate data types and constraints for each attribute.
SecondTeamI FirstTeamScor SecondTeamScor
MatchID MatchDate FirstTeamID
D e e
2021/12/2
M1 1 2 107 93
0
2021/12/2
M2 3 4 156 158
1
2021/12/2
M3 1 3 86 81
2
2021/12/2
M4 2 4 65 67
3
2021/12/2
M5 1 4 52 88
4
2021/12/2
M6 2 3 97 68
5

Answers:

a) create database sports;

b) Creating table with the given specification


create table team
(teamid int(1),
teamname varchar(10), primary key(teamid));

c) desc team;

● Inserting data:
mqsql> insert into team values(1,'Tehlka');
● Show the content of table - team:
select * from team;

● Creating another table:


create table match_details
-> (matchid varchar(2) primary key,
-> matchdate date,
-> firstteamid int(1) references team(teamid),
-> secondteamid int(1) references team(teamid),
-> firstteamscore int(3),
-> secondteamscore int(3));
19. Write following queries:
a) Display the matchid, teamid, teamscore whoscored more than 70 in first ining
along with team name.
b) Display matchid, teamname and secondteamscore between 100 to 160.
c) Display matchid, teamnames along with matchdates.
d) Display unique team names
e) Display matchid and matchdate played by Anadhi and Shailab.
Answers:
a) select match_details.matchid, match_details.firstteamid,
team.teamname,match_details.firstteamscore from match_details, team where
match_details.firstteamid = team.teamid and match_details.first
b) select match_details.matchid, match_details.firstteamid,
team.teamname,match_details.firstteamscore from match_details, team where
match_details.firstteamid = team.teamid and match_details.firstteamscore>70;

c) select matchid, teamname, firstteamid, secondteamid, matchdate from


match_details, team where match_details.firstteamid = team.teamid;

d) select distinct(teamname) from match_details, team where


match_details.firstteamid = team.teamid;
e) select matchid,matchdate from match_details, team where
match_details.firstteamid = team.teamid and team.teamname in
('Aandhi','Shailab');
20. Consider the following table and write the queries:

itemno Item dcode qty unitprice stockdate

S005 Ballpen 102 100 10 2018/04/22

S003 Gel Pen 101 150 15 2018/03/18

S002 Pencil 102 125 5 2018/02/25

S006 Eraser 101 200 3 2018/01/12

S001 Sharpner 103 210 5 2018/06/11

S004 Compass 102 60 35 2018/05/10

S009 A4 Papers 102 160 5 2018/07/17

a) Display all the items in the ascending order of stockdate.


b) Display maximum price of items for each dealer individually as per dcode from stock.
c) Display all the items in descending orders of itemnames.
d) Display average price of items for each dealer individually as per doce from stock
which avergae price is more than 5.
e) Diisplay the sum of quantity for each dcode.
Answers:
a) select * from stock order by stockdate;

b) select dcode,max(unitprice) from stock group by code;


c) select * from stock order by item desc;

d) select dcode,avg(unitprice) from stock group by dcode having avg(unitprice)>5;

e) select dcode,sum(qty) from stock group by dcode;


SQL Connectivity
21. Perform all the operations with reference to table ‘students’ through
MySQL-Python connectivity.
INPUT :-
import pymysql as ms

#Function to create Database as per users choice

def c_database():

try:

dn=input("Enter Database Name=")

c.execute("create database {}".format(dn))

c.execute("use {}".format(dn))

print("Database created successfully")

except Exception as a:

print("Database Error",a)

#Function to Drop Database as per users choice

def d_database():

try:

dn=input("Enter Database Name to be dropped=")

c.execute("drop database {}".format(dn))

print("Database deleted sucessfully")

except Exception as a:

print("Database Drop Error",a)


#Function to create Table
def c_table():
try:
c.execute('''create table students
(
rollno int(3),
stname varchar(20)
);
''')
print("Table created successfully")
except Exception as a:
print("Create Table Error",a)

#Function to Insert Data


def e_data():
try:
while True:
rno=int(input("Enter student rollno="))
name=input("Enter student name=")
c.execute("use {}".format('school'))
c.execute("insert into students values({},'{}');".format(rno,name))
db.commit()
choice=input("Do you want to add more record<y/n>=")
if choice in "Nn":
break
except Exception as a:
print("Insert Record Error",a)

#Function to Display Data


def d_data():
try:
c.execute("select * from students")
data=c.fetchall()
for i in data:
print(i)
except Exception as a:
print("Display Record Error",a)
db=ms.connect(host="localhost",user="root",password="root")
c=db.cursor()
while True:
print("MENU\n1. Create Database\n2. Drop Database \n3. Create Table\n4. Insert
Record \n5. Display Entire Data\n6. Exit")
choice=int(input("Enter your choice<1-6>="))
if choice==1:
c_database()
elif choice==2:
d_database()
elif choice==3:
c_table()
elif choice==4:
e_data()
elif choice==5:
d_data()
elif choice==6:
break
else:
print("Wrong option selected")
Output:

22 . using mysql connector


import mysql.connector as ms
db=ms.connect(host="localhost",user="root",passwd="root",database='school')
cn=db.cursor()
def insert_rec():
try:
while True:
rn=int(input("Enter roll number:"))
sname=input("Enter name:")
marks=float(input("Enter marks:"))
gr=input("Enter grade:")
cn.execute("insert into students
values({},'{}',{},'{}')".format(rn,sname,marks,gr))
db.commit()
ch=input("Want more records? Press (N/n) to stop entry:")
if ch in 'Nn':
break
except Exception as e:
print("Error", e)

def update_rec():
try:
rn=int(input("Enter rollno to update:"))
marks=float(input("Enter new marks:"))
gr=input("Enter Grade:")
cn.execute("update students set marks={},grade='{}' where
rno={}".format(marks,gr,rn))
db.commit()
except Exception as e:
print("Error",e)

def delete_rec():
try:
rn=int(input("Enter rollno to delete:"))
cn.execute("delete from students where rno={}".format(rn))
db.commit()
except Exception as e:
print("Error",e)
def view_rec():
try:
cn.execute("select * from students")

import mysql.connector as ms

db=ms.connect(host="localhost",user="root",passwd="root",database='school')

cn=db.cursor()

def insert_rec():

try:

while True:
rn=int(input("Enter roll number:"))

sname=input("Enter name:")

marks=float(input("Enter marks:"))

gr=input("Enter grade:")

cn.execute("insert into students values({},'{}',{},'{}')".format(rn,sname,marks,gr))

db.commit()

ch=input("Want more records? Press (N/n) to stop entry:")

if ch in 'Nn':

break

except Exception as e:

print("Error", e)

def update_rec():

try:

rn=int(input("Enter rollno to update:"))

marks=float(input("Enter new marks:"))

gr=input("Enter Grade:")

cn.execute("update students set marks={},grade='{}' where

rno={}".format(marks,gr,rn))

db.commit()

except Exception as e:

print("Error",e)

def delete_rec():
try:

rn=int(input("Enter rollno to delete:"))

cn.execute("delete from students where rno={}".format(rn))

db.commit()

except Exception as e:

print("Error",e)

def view_rec():

try:

cn.execute("select * from students")

data=c.fetchall()

for i in data:

print(i)

except Exception as e:

print("Error",e)

while True:

print("MENU\n1. Insert Record\n2. Update Record \n3. Delete Record\n4.

Display Record \n5. Exit")

ch=int(input("Enter your choice<1-4>="))

if ch==1:

insert_rec()

elif ch==2:

update_rec()
elif ch==3:

delete_rec()

elif ch==4:

view_rec()

elif ch==5:

break

else:

print("Wrong option selected")

except Exception as e:

print("Error",e)

while True:

print("MENU\n1. Insert Record\n2. Update Record \n3. Delete Record\n4.

Display Record \n5. Exit")

ch=int(input("Enter your choice<1-4>="))

if ch==1:

insert_rec()

elif ch==2:
update_rec()
elif ch==3:
delete_rec()
elif ch==4:
view_rec()
elif ch==5:
break
else:
print("Wrong option selected")

Output:
23. Write a menu-driven program to store data into a MySQL database named shop
and table customer as following:
1. Add customer details
2. Update customer details
3. Delete customer details
4. Display all customer details

import mysql.connector as ms
db=ms.connect(host="localhost",user="root",passwd="root",database='mydb')
cn=db.cursor()
def insert_rec():
try:
while True:
cid=int(input("Enter customer id:"))
cname=input("Enter name:")
city=input("Enter city:")
bill_amt=float(input("Enter bill amount:"))
cat=input("Enter category:")
cn.execute("insert into customer
values({},'{}','{}',{},'{}')".format(cid,cname,city,bill_amt,cat))
db.commit()
ch=input("Want more records? Press (N/n) to stop entry:")
if ch in 'Nn':
break
except Exception as e:
print("Error", e)

def update_rec():
try:
cn.execute("select * from customer")
data=cn.fetchall()
for i in data:
ci=i[0]
cna=i[1]
ct=i[2]
b=i[3]
c=i[4]
cid=int(input("Enter customer id to update:"))
if cid==ci:
ch_cname=input("Want to update Name, Press 'Y':")
if ch_cname.lower()=='y':
cname=input("Enter new name:")
else:
cname=cna
ch_city=input("Want to update city, Press 'Y':")
if ch_city.lower()=='y':
city=input("Enter new city:")
else:
city=ct
ch=input("Want to update bill amount, Press 'Y':")
if ch.lower()=='y':
bill_amt=float(input("Enter new bill amount:"))
else:
bill_amt=b
ch_cat=input("Want to update Category, Press 'Y':")
if ch_cat.lower()=='y':
cat=input("Enter new category:")
else:
cat=c
cn.execute("update customer set cname='{}', city='{}', bill_amt={},category='{}'
where cust_id={}".format(cname,city,bill_amt,cat,cid))
db.commit()
else:
print("Record Not Found...")
except Exception as e:
print("Error",e)
def delete_rec():
try:
cid=int(input("Enter customer id to delete:"))
cn.execute("delete from customer where cust_id={}".format(cid))
db.commit()
except Exception as e:
print("Error",e)
def view_rec():
try:
cn.execute("select * from customer")
data=cn.fetchall()
cnt=0
for i in data:
cnt=cnt+1
print("Record:",cnt)
print('~'*50)
print("Customer ID:",i[0])
print("Customer Name:",i[1])
print("City:",i[2])
print("Bill Amount:",i[3])
print("Category:",i[4])
print('~'*50)
except Exception as e:
print("Error",e)
while True:
print("MENU\n1. Insert Record\n2. Update Record \n3. Delete Record\n4.
Display Record \n5. Exit")
ch=int(input("Enter your choice<1-4>="))
if ch==1:
insert_rec()
elif ch==2:
update_rec()
elif ch==3:
delete_rec()
elif ch==4:
view_rec()
elif ch==5:
break
else:
print("Wrong option selected")

Output:
24. Modify the above program and display the customer details based on the following
menu:

1. Display customer details by city


2. Display customer details by bill amount
3. Display customer details by name
4. Display customer details by category

import mysql.connector as ms
db=ms.connect(host="localhost",user="root",passwd="root",database='mydb')
cn=db.cursor()

def byCity():
try:
city=input("Enter city to search:")
cn.execute("select * from customer where city='{}'".format(city))
data=cn.fetchall()
if data!=[]:
cnt=0
for i in data:
cnt=cnt+1
print('~'*100)
print("Record:",cnt)
print('~'*100)
print("Customer ID:",i[0])
print("Customer Name:",i[1])
print("City:",i[2])
print("Bill Amount:",i[3])
print("Category:",i[4])
else:
print("No records found for city ", city)
except Exception as e:
print("Error",e)

def byBillAmt():
try:
ba=input("Enter the bill amount:")
cn.execute("select * from customer where bill_amt={}".format(ba))
data=cn.fetchall()
if data!=[]:
cnt=0
for i in data:
cnt=cnt+1
print('~'*100)
print("Record:",cnt)
print('~'*100)
print("Customer ID:",i[0])
print("Customer Name:",i[1])
print("City:",i[2])
print("Bill Amount:",i[3])
print("Category:",i[4])
else:
print("No records found for bill amount ", ba)
except Exception as e:
print("Error",e)

def byName():
try:
name=input("Enter the name:")
cn.execute("select * from customer where cname='{}'".format(name))
data=cn.fetchall()
if data!=[]:
cnt=0
for i in data:
cnt=cnt+1
print('~'*100)
print("Record:",cnt)
print('~'*100)
print("Customer ID:",i[0])
print("Customer Name:",i[1])
print("City:",i[2])
print("Bill Amount:",i[3])
print("Category:",i[4])
else:
print("No records found for ", name)
except Exception as e:
print("Error",e)

def byCat():
try:
cat=input("Enter the cat:")
cn.execute("select * from customer where category='{}'".format(cat))
data=cn.fetchall()
if data!=[]:
cnt=0
for i in data:
cnt=cnt+1
print('~'*100)
print("Record:",cnt)
print('~'*100)
print("Customer ID:",i[0])
print("Customer Name:",i[1])
print("City:",i[2])
print("Bill Amount:",i[3])
print("Category:",i[4])
else:
print("No records found for category ", cat)
except Exception as e:
print("Error",e)

while True:
print('''
MENU
1.Display customer details by city
2.Display customer details by bill amount
3.Display customer details by name
4.Display customer details by category
5.Exit
''')
ch=int(input("Enter your choice<1-4>="))
if ch==1:
byCity()
elif ch==2:
byBillAmt()
elif ch==3:
byName()
elif ch==4:
byCat()
elif ch==5:
break
else:
print("Wrong option selected")

Output:

You might also like