Solutions for the given questions (32-37) from Class 12 Computer Science:
---
Question 32: Push and Pop Subject in Python
def PushSubject(SList, subject):
[Link](subject) # Acts as PUSH
return SList
def PopSubject(SList):
if SList:
return [Link]() # Acts as POP
else:
return "No subjects to remove."
# Example Usage
subjects = ["Math", "English", "Science"]
print("After Push:", PushSubject(subjects, "History"))
print("After Pop:", PopSubject(subjects))
---
Question 33: Manage Toy Data in CSV
import csv
# Function to add data
def add(toy_data):
with open('[Link]', mode='a', newline='') as file:
writer = [Link](file)
[Link](toy_data)
print("Data added successfully!")
# Function to search for toys priced above 500
def search():
with open('[Link]', mode='r') as file:
reader = [Link](file)
print("Toys priced above 500:")
for row in reader:
if row and float(row[2]) > 500:
print(row)
# Example Usage
add(["T001", "Toy Car", "600"])
search()
---
Question 34: SQL Queries
1. To display WNO, NAME, Gender in descending order of WNO:
SELECT WNO, NAME, GENDER FROM WORKER ORDER BY WNO DESC;
2. To display the names of female workers:
SELECT NAME FROM WORKER WHERE GENDER = 'F';
3. SQL Command for additional queries:
Workers born between '1987-01-01' and '1991-12-01':
SELECT WNO, NAME FROM WORKER WHERE DOB BETWEEN '1987-01-01' AND
'1991-12-01';
Count male workers who joined after '1986-01-01':
SELECT COUNT(*) FROM WORKER WHERE GENDER = 'M' AND DOJ > '1986-01-01';
Question No. 34 (OR):
SQL Commands:
1. (a) SELECT COUNT(*), DCODE FROM WORKER GROUP BY DCODE HAVING COUNT(*)
> 1;
This query will display the DCODE and the count of workers grouped by DCODE where the
number of workers is greater than 1.
SELECT COUNT(*) AS WorkerCount, DCODE
FROM WORKER
GROUP BY DCODE
HAVING COUNT(*) > 1;
Explanation:
COUNT(*) calculates the number of workers.
GROUP BY DCODE groups the records by department code (DCODE).
HAVING COUNT(*) > 1 filters the groups with more than 1 worker.
---
2. (b) SELECT DISTINCT(DEPARTMENT) FROM DEPT;
This query retrieves the distinct department names from the DEPT table.
SELECT DISTINCT DEPARTMENT
FROM DEPT;
Explanation:
DISTINCT ensures no duplicate department names are displayed.
Question 35: Python Script for Deleting Records
import [Link]
# Database connection
conn = [Link](
host="localhost",
user="learner",
password="blueice",
database="your_database_name"
)
cursor = [Link]()
# Deleting records
delete_query = "DELETE FROM category WHERE name = 'Stockable';"
[Link](delete_query)
[Link]()
print("Records deleted successfully!")
# Closing the connection
[Link]()
[Link]()
---
Question 36: Customer Records
1. File Type:
Use a CSV file as it is easy to manage and supports structured tabular data.
2. Python Functions:
import csv
# Function to add customer details
def add_customer(customer_id, name, address, aadhar_no):
with open('[Link]', mode='a', newline='') as file:
writer = [Link](file)
[Link]([customer_id, name, address, aadhar_no])
print("Customer details added successfully!")
# Function to display customers with ID > 1542
def display_customers():
with open('[Link]', mode='r') as file:
reader = [Link](file)
print("Customers with ID > 1542:")
for row in reader:
if row and int(row[0]) > 1542:
print(row)
# Example Usage
add_customer(1543, "John Doe", "Delhi", 123456789012)
display_customers()
---
Question 37: Network Setup
a. Most Suitable Place for the Server:
HR Center, as it has the highest number of computers (115), ensuring maximum resource
utilization.
b. Ideal Layout for Wired Connectivity:
Star Topology: Connect all blocks/centers to a central switch/router for efficient communication.
c. Device to Install:
Use Switches for connecting computers within each block and a Router for inter-block
communication.
d. Placement of Repeater:
Place repeaters between blocks that are more than 80 meters apart to ensure strong signal
strength.
e. Type of Network:
WAN (Wide Area Network) will be formed as the admission office in Delhi is over 1250 km away.
---