0% found this document useful (0 votes)
109 views22 pages

Practical Answrs

This document contains details about practical work completed by a student named Prithvi Panda for the Computer Science subject. It includes programs written by the student to perform tasks like calculating grades based on subject marks, generating random numbers, performing binary file operations, reading and processing text files, MySQL queries and more. The document consists of the student's name, roll number and details of 19 programs/queries completed by the student along with the dates.

Uploaded by

bhuyanashutosh5
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)
109 views22 pages

Practical Answrs

This document contains details about practical work completed by a student named Prithvi Panda for the Computer Science subject. It includes programs written by the student to perform tasks like calculating grades based on subject marks, generating random numbers, performing binary file operations, reading and processing text files, MySQL queries and more. The document consists of the student's name, roll number and details of 19 programs/queries completed by the student along with the dates.

Uploaded by

bhuyanashutosh5
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/ 22

KENDRIYA VIDYALAYA NO.

1 SAMBALPUR

PRACTICAL FILE

SESSION: 2022-23
CLASS - XII
COMPUTER SCIENCE
(083)
(PYTHON / MYSQL)

Submitted By: Submitted to:


Name: Prithvi Panda Mr. Lakhan Pal Singh

Roll No.12659850 PGT (Computer Science)


Certificate

This is to certify that Mast. Prithvi Panda, roll no: 12659850


has successfully completed the PRACTICAL FILE in the subject
Computer Science (083) laid down in the regulations of CBSE
in Class XII.

(Mr. Lakhan Pal Singh)


PGT Comp Sci
INDEX
S. Practical Date Remarks
No.
1. Write a program to define: -
a). Getdata(): - to input five subject marks (out of 100 ).
b). Calculate(): - to calculate percentage and Grade as per the following criteria:-
Percentage Grade
>90% A1
75-90 A
60-75 B
45-60 C
33-45 D
<33 E
c). Display():- to display percentage and grade on screen.
2. Write a python program to:
i. Create Generate() integer number randomly between 1 to 10 and return generated
number.
ii. Define function GetNum() to get integer number and compare with returned number
by Generate() function, if number matched then show “You are Won” otherwise “You
are Looser”.
3. Amritya Seth is a programmer, who has recently been given a task to write a python code
to perform the following binary file operations with the help of two user defined
functions/modules:
a. AddStudents() to create a binary file called STUDENT.DAT containing student
information – roll number, name and marks (out of 100) of each student.
b. GetStudents() to display the name and percentage of those students who have a
percentage greater than 75. In case there is no student having percentage > 75 the
function displays an appropriate message. The function should also display the average
percent.
4. Write a method/ function SHOW_TODO() in python to read contents from a text file
ABC.TXT and display those lines which have occurrence of the word ‘‘TO’’ or ‘‘DO’’.
5. Write a method/function COUNTLINES_ET() in python to read lines from a text file
REPORT.TXT, and COUNT those lines which are starting either with ‘E’ or starting
with ‘T’ and display the Total count separately.
6. A binary file named “TEST.dat” has some records of the structure [TestId, Subject,
MaxMarks, ScoredMarks].
Write a function in Python named DisplayAvgMarks(Sub) that will accept a subject as
an argument and read the contents of TEST.dat. The function will calculate & display the
Average of the ScoredMarks of the passed Subject on
screen.
7. i. Write a user defined function CreateFile() to input data for a record and add to
Book.dat file.
ii. Write a function CountRec(Author) in Python which accepts the Author name as
parameter and count and return number of books written by the given Author are stored
in the binary file “Book.dat”
8. Write a Python-MySQL Connectivity code to perform the following operation with
School Database Employee Table.
Operations:
1. Add New Employee Record
2. Display Existing Employee Details in Tabulation form
3. Update employee information with employee id
4. Remove existing by Employee id and show appropriate message in case record
not exist.
5. Search Employee record by Employee Name
9. Write a Python-MySQL Connectivity code to perform the following operation with
“Bill” Database Inventory Table.
Operations:
1. Make Entry of New Goods [ItemNo, Iname, Price, Quantity, Make]
2. Print Status of Stock
3. Modify Regular Selling Item Stock.
4. Search Item with Name of Item.
10. Write PushOn(Book) and Pop(Book) methods/functions in Python to add a new Book
and delete a Book from a List of Book titles, considering them to act as push and pop
operations of the Stack data structure.
11. Write a function in python, pushme (stock, item) and popme(stock ) to add a new item
and delete an item from the stock, considering them to act as push and pop operations of
the stack.
12. Two list Lname and Lage contains name of person and age of person respectively. A list
named Lnameage is empty. Write functions as details given below
(i) Push_na() :- it will push the tuple containing pair of name and age from Lname and
Lage whose age is above 50
(ii) Pop_na() :- it will remove the last pair of name and age and also print name and age
of removed person. It should also print “underflow” if there is nothing to remove
13. Write a program to create a function AddCustomer(Customer) in Python to add a new
Customer information into the stack (list) CStack and display the information.
14. Write a program to create a function DeleteCustomer() to delete a Customer information
from a list of CStack. The function delete the name of customer from the stack.
15. Write a Program in Python that defines and calls the following user defined functions:
(i) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each
record consists of a list with field elements as empid, name and mobile to store employee
id, employee name and employee salary respectively.
(ii) COUNTR() – To count the number of records present in the CSV file named
‘record.csv’.
16. Table: EMPLOYEES
Empid Firstname Lastname Address City
010 Ravi Kumar Raj nagar GZB
105 Harry Waltor Gandhi nagar GZB
152 Sam Tones 33 Elm St. Paris
215 Sarah Ackerman 440 U.S. 110 Upton
244 Manila Sengupta 24 Friends street New Delhi
300 Robert Samuel 9 Fifth Cross Washington
335 Ritu Tondon Shastri Nagar GZB
400 Rachel Lee 121 Harrison St. New York
441 Peter Thompson 11 Red Road Paris
Table: EMPSALARY
Empid Salary Benefits Designation

010 75000 15000 Manager

105 65000 15000 Manager

152 80000 25000 Director

215 75000 12500 Manager

400 32000 7500 Salesman

441 28000 7500 salesman

501 18000 6500 Clerk

Give the Output of following SQL commands:


(i) Select Employee.firstname, empsalary, salary from employees, empsalary where
designation = ‘Salesman’ and Employees.empid=Empsalary.empid;
(ii) Select count(distinct designation) from empsalary;
(iii) Select designation, sum(salary) from empsalary group by designation having
count(*) >2;
(iv) Select sum(benefits) from empsalary where designation =’Clerk’;
v) Write SQL Query for Equi join and Non-equi join.

17. Write a query to create the following table with Show structure of Table and Number of
Tables in Current working Database.
Table – Customer
Name of Field Datatype Size Constraints
Cno Integer 5 Primary Key
Cname Varchar 30 Not Null
Gender Char 1
DOB Date - >= “2003-01-01”
Amountpaid Float 10,2 Default “Free”
Remarks Varchar 100
18. A Stationery shop MyBag has decided to maintain its inventory of items using
MySQL. As a database administer, Rahul has created the database and table as
per the following :
Name of the database -MyBag
Name of the table - ITEMS
The attributes of ITEMS are as follows: ItemNo – Numeric, ItemName – Character of size
20 ,Scode –Numeric,Quantity –Numeric
Table: ITEMS
ItemNo ItemName Scode Quantity

2005 Sharpener Classic 23 60

2002 Get Pen Premium 21 150

2006 Get Pen Classic 21 250

2001 Eraser Small 22 220

2004 Eraser Big 22 110

19. A music store MySports is considering to maintain their inventory using SQL to store the
data. The detail is as follow:
o Name of the database – MySports
o Name of the table – Sports
The attributes of SPORTS are as follows:
 SCode – character
 SportName – character of size 20
 Noofplayers – numeric
 coachname – character of size 20
Table: SPORTS
20. Table: SPORTS
SCode SportName No. of players Coachname

S001 Cricket 21 Rahul Dravid

S002 Football 25 Roshan Lal

S003 Hockey 40 Sardar Singh

S004 Cricket 19 Chetan Sharma

S005 Archery 12 Limbaram

S006 Shooting 17 Deepika Kumari


a) Create Table “SPORTS”
b) Display details about structure of table.
c) Insert the following data into the attributes SCode, SportName and No. of players
respectively in the given table SPORTS.
SCode = S007, SportName = “Kabbadi” and Noofplayers = 15
d) To delete Column “ SCode” and Another Column “SID” with appropriate column
type and constraints.

****************** Best of Luck ***************


SOLUTIONS

1. import pickle as p

def Getdata():

print("----Marks out of 100----")

f=open("Student.dat","wb")

e=int(input("Enter marks of English:"))

c=int(input("Enter marks of Chemistry:"))

p=int(input("Enter marks of Physics:"))

m=int(input("Enter marks of Mathematics:"))

c=int(input("Enter marks of Comp.Sc:"))

print(e+c+p+m+c)

lst=[e,c,p,m,c]

p.dump(lst,f)

f.close()

def Calculate():

f=open("student.dat","rb")

lst=[e,c,p,m,c]

s=e+c+p+m+c

per=(s/500)*100
print("Percentage:",per)

if per>90:

grd="A1"

elif per>=75:

grd="A"

elif per>=60:

grd="B"

elif per>=45:

grd="C"

elif per>33:

grd="D"

elif per<=33:

grd="E"

else:

grd="--Padh le--"

print("Grade:",grd)

2. import random as r

def Generate():

a=r.randint(1,10)

return a

def GetNum():
a=Generate()

b=int(input("Enter a number between 1-10:"))

if a==b:

print("you are Winner")

else:

print("Your are Looser")

3. import pickle as p

def AddStudents():

f=open("Student.dat","wb")

rno=int(input("Enter the Roll No.:"))

nm=input("Enter the Name:")

mk=int(input("Enter the Marks:"))

per=int(input("Enter the Percentage:"))

per=(mk/100)*100

lst=[rno,nm,mk,per]

p.dump(lst,f)

f.close()

def GetStudents():

f=open("Student.dat","rb")

while True:

try:

rec=p.load(f)
if rec[3]>75:

print(rec)

else:

print("--No Student Found--")

except EOFError:

break

f.close()

4. def SHOW DATA():


f=open(“ABC.txt”,”r”)
data=f.split()
print(count(data))
f.close()

5. def COUNTLINES():

f=open("Report.txt","r")

c=0

for text in f.readlines():

for word in text.split():

if word=="%E" or "%T":

c=c+1
print(c)

f.close()

6. import pickle as p

def DisplayAvgMarks():

f=open("TEST.dat","wb")

d=f.load()

s=0

n=0

for i in d:

s+=i[3]

n+=1

avmrk=s/n

print(f’Average Marks in {Sub}:{avmrk}’)

7. import pickle as p

def CreateFile():

f=open("Book.dat","wb")

At=input("Enter the Name of Author:")

bk=input("Enter the name of book written")

l=[At,bk]

p.dump(l,f)

f.close()
f=open("Book.dat","rb")

while True:

try:

d=p.load(f)

print(d[0],"\t",d[1])

except EOFError:

break

f.close()

def CountRec(Author):

f=open("Book.dat","rb")

r=p.load(f)

c=0

for i in r:

if r[0]==Author:

c=c+1

print(c)

f.close()

8. print(“Menu”)

print(“1.Add”)

print(“2.Display”)

print("3.Update")
print("4.Delete")
print("5.Search")

import mysql.connector as con


mydb=con.connect(host="localhost",user="root",pass
wd="tiger",database="test")
s=input("Do you want to use the program(Yes/No):") while s=="Yes"or
s=="yes"or s=="y"or s=="Y":
n=int(input("Enter a number:"))
#Add
if n==1:
a=input("Enter Employee ID:") b=input("Enter
Employee Name:") c=input("Enter Salary:")
d=input("Enter DeptID:") e=input("Enter
Bonus:") mycur=mydb.cursor()
query=("Insert into Employee(EmpID, EmpName,Salary, Dept_ID,
Bonus) values (%s,%s,%s,%s,%s)")

values=(a,b,c,d,e) dataset=mycur.execute(query, values)


for i in mycur:
print(i)

#Display(T)

elif n==2:
mycur=mydb.cursor() dataset=mycur.execute("Select * from
Employee, Department where
Employee.Dept_ID=Department.DeptID")
for i in mycur:
print(i)

#Update
elif n==3:
a=input("Enter Employee ID which needs to be updated:")
b=input("Enter Employee Name:") c=input("Enter
Salary:") d=input("Enter DeptID:")
e=input("Enter DeptName:") f=input("Enter
Bonus:") g=input("Enter Location:")
mycur=mydb.cursor()
dataset=mycur.execute("Update Employee, Department set
EmpName='"+b+"', Salary='"+c+"', Dept_ID='"+d+"',
DeptName='"+e+"', Bonus='"+f+"', Location='"+g+"' where
EmpID='"+a+"' and Employee.Dept_ID=Department.DeptID")
print("Data Updated Successfully.")

#Delete
elif n==4:
a=input("Enter Employee ID which you want to delete:")
mycur=mydb.cursor() dataset=mycur.execute("Delete from
Employee
where EmpID='"+a+"'")
print("Data Deleted Successfully.") print("Updated
Table") mycur1=mydb.cursor()
dataset=mycur1.execute("Select * from Employee,
Department where
Employee.Dept_ID=Department.DeptID")
for i in mycur1:
print(i)

#Search
elif n==5:
x=input("Enter Employee Name:") mycur=mydb.cursor()
dataset=mycur.execute("Select * from Employee,
Department where EmpName='"+x+"' and
Employee.Dept_ID=Department.DeptID")
for i in mycur:
print(i)

9. import mysql.connector as con

mydb=con.connect(host="local host",user="root", passwd="tiger",


database="School")

cur=mydb.cursor()

#1.a=cur.execute("insert into Inventory


(ItemNo,Iname,Price,Quantiy,Make)values (1,box,200,1000,160)")

#2.a=cur.execute("select * from Inventory")

#3.a=cur.execute("update Inventory itemNo=3 where Iname=box")

#4.a=cur.execute("select * from Inventory where Iname="box"")

for i in a:

print(a)

10. def PushOn(Book):

a=input(“Enter the book name:”)


Book=Book.append(a)

Print(“Added Successfully”)

def Pop(Book):

Book=Book.pop()

Print(“Popped Successfully”)

11. def push(stk, item):

stk.append(item)

top=len(stk)-1

def pop(stk):

if (isempty(stk)):

return ('underflow')

else:

i=stk.pop()

if (len(stk)==0):

top=None

else:

top=top[s]-1

return i

12. Lname = ['narender', 'jaya', 'raju', 'ramesh', 'anita', 'Piyush']

Lage = [45, 23, 59, 34, 51, 43]

Lnameage = []
def push_na():

for x in range(len(Lname)):

if Lage[x] > 50:

Lnameage.append((Lname[x], Lage[x]))

print(Lnameage)

def pop_na():

if len(Lnameage) == 0:

print("Underflow")

else:

t = Lnameage.pop()

print("The name removed is ", t[0])

print("The age of person is ", t[1])

push_na()

pop_na()

13. CStack=[ ]
def AddCustomer(Customer):
CStack.append(Customer)
if len(CStack)==0:
print (“Empty Stack”)
else:
print (CStack)

14. CStack=[ ]
def DeleteCustomer():
if (CStack ==[]):
print(“There is no customer”)
else:
print(“Record deleted, CStack.pop())

15.i. import csv


P =open(“record.csv”,’w’)
Empd=csv.writer(p)
for i in range ():
Empid=int(input(“enter id :”)
Empname =input(“enter name:”)
Empsal =int(input(“enter salary:”)
Emprec =[Empid,Empname,Empsal]
Empd.writerow(Emprec)
p.close( )
ii. import csv
P = open(“record.csv”,’r’)
Rec = csv.reader(P)
Print(“no of records in file”)
p.close( )

16.i.

Firstname Salary
Rachel 32000
Peter 28000

ii.

Designation
Manager 3
Director 1
Salesman 2
clerk 1

iii.

Designation Sum(salary)
Manager 215000

iv.

6500

v. Equi join:-

select * from EMPLOYEES,EMPSALARY where


EMPLOYEES.Empid=EMPSALARY.Empid;

Non Equi join:-

select * from EMPLOYEES,EMPSALARY where


EMPLOYEES.Empid=EMPSALARY.Designation;

17. create table Customer Cno int(5) primary key, Cname varchar(30)
notnull, Gender char(1), DOB date(>=2003-01-01), Amountpaid float(10,2),
Remark varchar(100);

18. create table Sports Scode char, SportName char(20), Noofplayers int,
coachname char(20);

19.create table Sports Scode char, SportName char(20), Noofplayers int,


coachname char(20);
20.a. Create table SPORTS SCode varchar(10), SportName Char (20), No.
of players int(10), Coachname char(20);

b. desc SPORTS;

c.insert into SPORTS (SCode, SportName, No. of players) values (“S0007”,


“Kabbadi”, “15”);

d. ALTER TABLE SPORTS DROP COLUMN SCODE;


ALTER TABLE ADD SID VARCHAR(20) PRIMARY KEY;

1. Enter marks of English:98


Enter marks of Chemistry:86
Enter marks of Physics:90
Enter marks of Mathematics:91
Enter marks of Comp.Sc:87
453
2. Generate()
9
Enter a number between 1-10:6
You are Looser
Enter a number between 1-10:2
you are Winner
3. AddStudents()
Enter the Roll No.:10
Enter the Name:Ramlal
Enter the Marks:99
Enter the Percentage:99
GetStudents()
[10, 'Ramlal', 99, 99.0]
4. SHOW DATA()
15
5. COUNTLINES()
15
6. DisplayAvgMarks()
Enter the ID:1
Enter the Subject:English
Enter the Max Marks:99
Enter the Scored Marks:92
Average of Scored Marks: 46.0
7. CreateFile()

Enter the Name of Author:Chetan Bhagat

Enter the name of book writtentwo states

Chetan Bhagat two states

CountRec(Author)

8.

9.

10

11. stk=[1,2,3,4]

push(stk,5)

print(stk)

[1, 2, 3, 4, 5]

12. [('raju', 59), ('anita', 51)]

The name removed is anita

The age of person is 51


13.

You might also like