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

Python - Roshni ( 3 )

Important Questions solved

Uploaded by

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

Python - Roshni ( 3 )

Important Questions solved

Uploaded by

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

Solutions for the given questions (32-37) from Class 12 Computer Science:

---

Question 32: Push and Pop Subject in Python

def PushSubject(SList, subject):


SList.append(subject) # Acts as PUSH
return SList

def PopSubject(SList):
if SList:
return SList.pop() # 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('toydata.csv', mode='a', newline='') as file:
writer = csv.writer(file)
writer.writerow(toy_data)
print("Data added successfully!")

# Function to search for toys priced above 500


def search():
with open('toydata.csv', mode='r') as file:
reader = csv.reader(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 mysql.connector

# Database connection
conn = mysql.connector.connect(
host="localhost",
user="learner",
password="blueice",
database="your_database_name"
)

cursor = conn.cursor()

# Deleting records
delete_query = "DELETE FROM category WHERE name = 'Stockable';"
cursor.execute(delete_query)
conn.commit()

print("Records deleted successfully!")

# Closing the connection


cursor.close()
conn.close()

---

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('customers.csv', mode='a', newline='') as file:
writer = csv.writer(file)
writer.writerow([customer_id, name, address, aadhar_no])
print("Customer details added successfully!")

# Function to display customers with ID > 1542


def display_customers():
with open('customers.csv', mode='r') as file:
reader = csv.reader(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.
---

You might also like