0% found this document useful (0 votes)
3 views11 pages

Practical Practice

The document contains practical programming questions for Grade 12 Computer Science, focusing on file handling in Python, including functions for adding and searching employee records, mobile phone data, stationery items, and furniture records. It also includes SQL queries for various database operations involving activities, coaches, stock, and traders. Each section provides code examples and SQL statements to demonstrate the required functionality.

Uploaded by

anikkumar.inbox
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)
3 views11 pages

Practical Practice

The document contains practical programming questions for Grade 12 Computer Science, focusing on file handling in Python, including functions for adding and searching employee records, mobile phone data, stationery items, and furniture records. It also includes SQL queries for various database operations involving activities, coaches, stock, and traders. Each section provides code examples and SQL statements to demonstrate the required functionality.

Uploaded by

anikkumar.inbox
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

Computer Science

Grade 12
Practical Practice questions
Q1. Write code for following given functions:
(a) ADD() – To accept and add data of an employee to a binary file ‘[Link]’.
Each record consists of a list with field elements as empid, name, salary and mobile
to store employee id, employee name, salary and employee mobile number
respectively.
(b) Search() – To search an employee records on basis of given employee id present
in the binary file named ‘[Link]’.
import pickle
def ADD():
f = open("[Link]", "ab")
empid = int(input("Enter Employee ID: "))
name = input("Enter Name: ")
salary = float(input("Enter Salary: "))
mobile = input("Enter Mobile Number: ")

record = [empid, name, salary, mobile]


[Link](record, f)
[Link]()

def Search():
f = open("[Link]", "rb")
eid = int(input("Enter Employee ID to search: "))
found = False

try:
while True:
record = [Link](f)
if record[0] == eid:
print("Employee Found:", record)
found = True
break
except EOFError:
pass

if not found:
print("Employee not found")
[Link]()
Q2. Write code for following given functions:
(i) AddRecord() – To accept and add data of Mobile phones to a CSV file
‘Mobile_Phones.csv’. Each record consists of a list with field elements as ModelNo,
MobileName, Manufacturer and Price to store model number, mobile name,
manufacturer and price respectively.
(ii) Find() – To search the records of mobiles manufactured by Apple present in the
CSV file named ‘Mobile_Phones.csv’
import csv

def AddRecord():
f = open("Mobile_Phones.csv", "a", newline='')
writer = [Link](f)

model = input("Enter Model No: ")


name = input("Enter Mobile Name: ")
manufacturer = input("Enter Manufacturer: ")
price = float(input("Enter Price: "))

[Link]([model, name, manufacturer, price])


[Link]()

import csv

def Find():
f = open("Mobile_Phones.csv", "r")
reader = [Link](f)

for row in reader:


if row[2] == "Apple":
print(row)
[Link]()

Q3. Write a program in Python that defines and calls the following user-defined
functions:
(a) Add_Item() – To accept and add data of stationery items to a CSV file
‘[Link]’. Each record consists of a list with field elements as Item_Id,
Item_name and Item_price to store item id, item_name and item_price respectively.
(b) Count() – To count the total number of stationery items in the CSV file.
Answer 1:
import csv
def Add_Item():
f = open("[Link]", "a", newline="")
w = [Link](f)
ch = 'y'
while [Link]() == 'y':
item_id = int(input("Enter Item Id: "))
item_name = input("Enter Item Name: ")
item_price = float(input("Enter Item Price: "))
[Link]([item_id, item_name, item_price])
ch = input("Add more records (y/n): ")
[Link]()
def Count():
f = open("[Link]", "r")
r = [Link](f)
c=0
for i in r:
c += 1
print("Total number of stationery items:", c)
[Link]()
Add_Item()
Count()
Q4. Write a method SHOWLINES() in Python to read lines from text file ‘[Link]’ and

display the lines which start with ‘A’ .

Example: If the file content is as follows:

An apple a day keeps the doctor away.

We all pray for everyone’s safety.

A marked difference will come in our country


The SHOWLINES() function should display the output as:

An apple a day keeps the doctor away.

A marked difference will come in our country

def SHOWLINES():
f = open("[Link]", "r")
for line in [Link]():
if [Link]('A'):
print(line, end='')
[Link]()

Q5. Write a Program in Python that defines and calls the following user defined functions:
(a) add() – To accept and add data of an furniture to a CSV file ‘[Link]’. Each record
consists of a list with field elements as fid, fname and fprice to store furniture id, furniture name
and furniture price respectively.
(b) search()- To display the records of the furniture whose price is more than 10000.

Answer 1:
import csv
def add():
f = open("[Link]", "a", newline="")
w = [Link](f)
ch = 'y'
while [Link]() == 'y':
fid = int(input("Enter Furniture Id: "))
fname = input("Enter Furniture Name: ")
fprice = float(input("Enter Furniture Price: "))
[Link]([fid, fname, fprice])
ch = input("Add more records (y/n): ")
[Link]()
def search():
f = open("[Link]", "r")
r = [Link](f)
print("Furniture costing more than 10000:")
for i in r:
if float(i[2]) > 10000:
print(i)
[Link]()
add()
search()

MYSQL Questions

Q1. Write SQL queries for (i) to (iv) on the basis of tables

Table: ACTIVITY

ACode ActivityName ParticipantsNum PrizeMoney ScheduleDate

1001 Relay 100x4 16 10000 23-Jan-2020

1002 High jump 10 12000 12-Dec-2019

1003 Shot Put 12 8000 14-Feb-2020

1005 Long Jump 12 9000 01-Jan-2020

1008 Discuss Throw 10 15000 19-Mar-2020

Table: COACH

[Link]. Name Acode

1 Ahmad Hussain 1001


2 Ravinder 1008

3 Janila 1002

4 Naaz 1003

5 Zameel 1004

i. Write a query to display activity name and coach name in order of their coach
name

ii. Write a query to display sum of prize money where participants number is
greater than 13

iii. Write a query to display coach name, activity name and schedule date in
descending order of schedule date

iv. Display coach name with their acode for coaches whose name has a as second
character.

i. Display activity name and coach name in order of coach name


SELECT ActivityName, Name
FROM ACTIVITY, COACH
WHERE [Link] = [Link]
ORDER BY Name;

ii. Display sum of prize money where participants number is greater than 13
SELECT SUM(PrizeMoney)
FROM ACTIVITY
WHERE ParticipantsNum > 13;

iii. Display coach name, activity name and schedule date in descending order of
schedule date
SELECT Name, ActivityName, ScheduleDate
FROM ACTIVITY, COACH
WHERE [Link] = [Link]
ORDER BY ScheduleDate DESC;

iv. Display coach name with their acode for coaches whose name has 'a' as second
character
SELECT Name, Acode
FROM COACH
WHERE Name LIKE '_a%';

Q2. Write SQL queries for (i) to (iv) on the basis of tables

Table: STOCK
Item
ItemNo Dcode Qty UnitPrice StockDate

5005 Ball Pen 0.5 102 100 16 2010-03-31

5003 Ball Pen 0.25 102 150 20 2010-01-01

5002 Gel Pen Premium 101 125 14 2010-02-14

5006 Gel Pen Classic 101 200 22 2009-01-01

5001 Eraser Small 102 210 5 2009-03-19

5004 Eraser Big 102 60 10 2009-12-12

5009 Sharpener Classic 103 160 8 2009-01-23

Table: DEALERS

Dcode DName

101 Reliable Stationers

103 Classic Plastics

102 Clear Deals


i. Write the query to display item, dname, quantity and unit price in order of
quantity of their stock
ii. Write the query to display sum of quantity for each Dcode
iii. Write the query to display Dname, stoxk date in descending order of stock date
iv. Write the query to display details of stick in order of Item name.

i. Display item, dname, quantity and unit price in order of quantity


SELECT Item, DName, Qty, UnitPrice
FROM STOCK, DEALERS
WHERE [Link] = [Link]
ORDER BY Qty;

ii. Display sum of quantity for each Dcode


SELECT Dcode, SUM(Qty)
FROM STOCK
GROUP BY Dcode;

iii. Display Dname and stock date in descending order of stock date
SELECT DName, StockDate
FROM STOCK, DEALERS
WHERE [Link] = [Link]
ORDER BY StockDate DESC;

iv. Display details of stock in order of Item name


SELECT *
FROM STOCK
ORDER BY Item;
Q1. Write SQL queries for (i) to (iii) on the basis of tables ITEMS and TRADERS:
Table: ITEMS
CODE INAME COMPANY TCODE
QTY PRICE

1001 XENITA T01


DIGITAL PAD 12i 120 11000
1006 SANTORA T02
LED SCREEN 40 70 38000

1004 GEOKNOW T01


CAR GPS SYSTEM 50 21500

1003 DIGICLICK T02


DIGITAL CAMERA 12X 160 8000

1005 STOREHOME T03


PEN DRIVE 32GB 600 1200

Table :TRADERS
TCode
TName CITY

T01
ELECTRONIC SALES MUMBAI

T03
BUSY STORE CORP DELHI

T02
DISP HOUSE INC CHENNAI

Answer 2: SQL Queries


(i) Display item name and price where price is between 10000 and 22000
SELECT INAME, PRICE
FROM ITEMS
WHERE PRICE BETWEEN 10000 AND 22000;
(ii) Display TName and Iname where quantity > 100
SELECT TName, INAME
FROM ITEMS, TRADERS
WHERE [Link] = [Link]
AND QTY > 100;
(iii) Display price of item whose trader city is Chennai
SELECT PRICE
FROM ITEMS, TRADERS
WHERE [Link] = [Link]
AND CITY = 'CHENNAI';
(iv) Display average price of items on basis of TCODE
SELECT TCODE, AVG(PRICE)
FROM ITEMS
GROUP BY TCODE;

Q2. Consider the following tables GAMES and PLAYER. Write SQL commands for
the statements (i) to (iv)
Table: GAMES
G GameName Participants PrizeMoney ScheduleDate
C
o
d
e

1 Carom Board 2 5000 23-Jan-2004


0
1

1 Badminton 2 12000 12-Dec-2003


0
2

1 Table Tennis 4 8000 14-Feb-2004


0
3

1 Chess 2 9000 01-Jan-2004


0
5

1 Lawn Tennis 4 25000 19-Mar-2004


0
8

Table: PLAYER
PCode Name Gcode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jatin 101
4 Nazneen 103

Answer 2: SQL Queries


(i) Display all GameName, player name with their Gcodes
SELECT GameName, Name, [Link]
FROM GAMES, PLAYER
WHERE [Link] = [Link];
(ii) Display Game name, schedule date and pcode of games having PrizeMoney > 7000
SELECT GameName, ScheduleDate, PCode
FROM GAMES, PLAYER
WHERE [Link] = [Link]
AND PrizeMoney > 7000;
(iii) Display GAMES table in ascending order of ScheduleDate
SELECT * FROM GAMES
ORDER BY ScheduleDate ASC;
(iv) Display player name, game name and prize money where 4th character of name is ‘I’
SELECT Name, GameName, PrizeMoney
FROM GAMES, PLAYER
WHERE [Link] = [Link]
AND Name LIKE '___I%';

You might also like