0% found this document useful (0 votes)
87 views12 pages

Answer Key For Pb-Ii

Uploaded by

jdjamal5383
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)
87 views12 pages

Answer Key For Pb-Ii

Uploaded by

jdjamal5383
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/ 12

SECTION A

1. (iii) ['CBS', ' Exams2024-25']


2. (d) CREATE
3. (d) CHAR
4. (ii) 'Mi$nium Mi$stones'
5. (B) WAN
6. f=open("C:\hologram.txt","r")
7. (i) ('a', 'p', 'p', 'l', 'e', 4)
8. (iii) print(stu_stream["Ravi"])
9. (c) else
10. (i) x is now 50
11. (B) 1.0, 4.0
12. (b) Tuple
13. (c) def study(a, b=2, c=5):
14. (A) True
15. (b) alter
16. (A) Details of all employees whose names start with 'A'
17. (c) 3
18. (i)

19. (b) Guided and Unguided


20. (C) A is True but R is False
21. (A) Both A and R are true and R is the correct explanation for A

SECTION B
22.
(a) Difference between lists and tuples:

• List: Mutable, allows modifications.


• Tuple: Immutable, cannot be modified.

(b) emp_records = [

['E1', 'Shalini', 5000, 'Sales'],

['E2', 'Drishyam', 5500, 'Purchase'],

['E3', 'Rohini', 7000, 'Purchase'],


['E4', 'Kalaam', 6000, 'Finance'],

['E5', 'Seema', 8000, 'HR']

print(emp_records[3][2]) # Output: 6000

23.
(a) Advantage and disadvantage of Mesh topology:

• Advantage: Provides high fault tolerance.


• Disadvantage: Expensive due to more cables and configuration.

(b) Expansions:

• SMTP: Simple Mail Transfer Protocol


• POP3: Post Office Protocol version 3

24.
Errors and corrections in the given code:
Corrected code:

d1 = dict() # Error: dict[] -> dict()


i=1
n = int(input("Enter number of entries:")) # Error: input returns string, convert to int
while i <= n:
a = input("Enter name:")
b = input("Enter age:")
d1[a] = b # Error: dl(a) -> d1[a]
i=i+1

l = d1.keys() # Error: dl.key[] -> d1.keys()


for i in l:
print(i, '\t', d1[i]) # Error: 'dl [i]' -> d1[i]
25.
I.
(a) Sort list car in descending order (without changing original list):

sorted_car = sorted(car, reverse=True)


(b) Insert 'Xiaomi' at the 5th position in phone:

phone.insert(4, 'Xiaomi')
II.
(a) Remove 'Audi' from car:

if 'Audi' in car:
car.remove('Audi')
(b) Add elements of more_cars to the end of car:

car.extend(['Audi', 'Hyundai', 'Nissan', 'Volkswagen'])

26.
Correct option:

1. first + float(second) returns 2.0.

27.
(i) Set Pcode as Primary Key:

ALTER TABLE FITNESS ADD PRIMARY KEY (Pcode);


Or
Disallow NULL values for Pname:

ALTER TABLE FITNESS MODIFY Pname VARCHAR(50) NOT NULL;


(ii) Add manfc_date column:

ALTER TABLE FITNESS ADD manfc_date DATE;


Or
Change datatype of Pname:

ALTER TABLE FITNESS MODIFY Pname VARCHAR(100);

28.
Outputs and ranges for variables:

• Possible outputs: (b) 30#40#50#


• Minimum value of Lower: 1
• Maximum value of Upper: 4
SECTION-C
29.
(a) Output for the first code:

d = {"spade": 15, "club": 7, "heart": 9}


str1 = ""
for key in d:
str1 = str1 + str(key) + "$" + "\n"
str2 = str1[:-1]
print(str2)
Output:

spade$
club$
heart$

OR

(b) Output for the second code if input is 'abcd':

Input: abcd
bigInt = 2 # 'c' and 'd' (greater than 'm')
littleInt = 2 # 'a' and 'b' (less than or equal to 'm')
otherInt = 0 # No special characters or digits
inputStr.isdigit() = False
Output:

2
2
0
False
30.
(a) Function to display all 4-letter words from going_places.txt:

def display_4_letter_words():
with open("going_places.txt", "r") as file:
content = file.read().split()
for word in content:
if len(word) == 4:
print(word, end=" ")

Output for sample text in the question:


back over sink back

OR

(b) Function to count uppercase, lowercase, digits, and spaces in Words.txt:

def count_characters():
with open("Words.txt", "r") as file:
content = file.read()
upper = sum(1 for c in content if c.isupper())
lower = sum(1 for c in content if c.islower())
digits = sum(1 for c in content if c.isdigit())
spaces = sum(1 for c in content if c.isspace())
print("Uppercase:", upper)
print("Lowercase:", lower)
print("Digits:", digits)
print("Spaces:", spaces)
31.
(a) Functions to perform operations on MovieStack:

MovieStack = []

def push_movie(new_movie):
MovieStack.append(new_movie)

def pop_movie():
if not MovieStack:
print("Underflow")
return None
return MovieStack.pop()

def display_movies():
if not MovieStack:
print("No more movies")
else:
for movie in reversed(MovieStack):
print(movie)

OR

(b) Function to push TATA cars to stack:

def Push(Vehicle):

stack = []

for car, maker in Vehicle.items():

if "TATA" in maker.upper():
stack.append(car)

return stack

Vehicle = {"Santro": "Hyundai", "Nexon": "TATA", "Safari": "Tata"}

stack = Push(Vehicle)

print(stack) # Output: ['Nexon', 'Safari']

SECTION-D
32.
(a) SQL Queries:

(i) Display computer product records in descending order of price:

SELECT * FROM COMPUTER ORDER BY PRICE DESC;

(ii) Display the number of input and output devices:

SELECT TYPE, COUNT(*) FROM COMPUTER GROUP BY TYPE;


(iii) Display product name, price, and quantity of products made by LOGITECH:

SELECT PROD_NAME, PRICE, QTY_SOLD FROM COMPUTER C, SALES S


WHERE C.PROD_ID = S.PROD_ID AND COMPANY = 'LOGITECH';
(iv) Increase the price of CANON products by 5%:

UPDATE COMPUTER SET PRICE = PRICE * 1.05 WHERE COMPANY = 'CANON';

OR

(b) Outputs for SQL Queries:

(i) SELECT MIN(PRICE), MAX(PRICE) FROM COMPUTER;

Output:
MIN(PRICE): 200, MAX(PRICE): 4300

(ii) SELECT COMPANY, COUNT(*) FROM COMPUTER GROUP BY COMPANY


HAVING COUNT(COMPANY) > 1;
Output:
LOGITECH: 2, CANON: 2

(iii) SELECT PROD_NAME, QTY_SOLD FROM COMPUTER C, SALES S WHERE


C.PROD_ID = S.PROD_ID AND TYPE = 'INPUT';

Output:
KEYBOARD: 2, MOUSE: 3, JOYSTICK: 2

(iv) SELECT PROD_NAME, COMPANY, QUARTER FROM COMPUTER C, SALES S


WHERE C.PROD_ID = S.PROD_ID;

Output:
LASER PRINTER: CANON: 1, KEYBOARD: LOGITECH: 2, MOUSE: LOGITECH: 2, JOYSTICK:
IBALL: 1

33.
(a) Python functions for Winner_details.csv:

(i) Calculate average points scored by winners in the 3rd position:

python
Copy code
import csv

def average_points():
total_points = count = 0
with open("Winner_details.csv", "r") as file:
reader = csv.reader(file)
for row in reader:
if row[3] == '3': # Position is 3
total_points += int(row[2]) # Points scored
count += 1
if count:
print("Average Points:", total_points / count)
else:
print("No winners in the 3rd position")

(ii) Insert a new record into the file:

python
Copy code
def insert_record(new_record):
with open("Winner_details.csv", "a", newline="") as file:
writer = csv.writer(file)
writer.writerow(new_record)

# Example: insert_record(['Aryan', 'Coding Contest', 50, 1])


34.
(a) Primary Key of the table:

• Primary Key: FID


• Reason: It uniquely identifies each record in the table.

(b) Degree and Cardinality after adding 3 records and 2 columns:

• Degree: 7 (5 existing columns + 2 new columns)


• Cardinality: 9 (6 existing records + 3 new records)

(c) (i) SQL command to insert one record:

sql
Copy code
INSERT INTO FURNITURE (FID, NAME, DATE_OF_PURCHASE, COST, DISCOUNT)
VALUES ('T012', 'Coffee Table', '2022-01-15', 18000, 5);

(ii) Increase price of furniture where discount > 10:

sql
Copy code
UPDATE FURNITURE SET COST = COST + 1000 WHERE DISCOUNT > 10;

OR

(i) Delete records where price < 20000:

sql
Copy code
DELETE FROM FURNITURE WHERE COST < 20000;

(ii) Add a column WOOD:

sql
Copy code
ALTER TABLE FURNITURE ADD WOOD VARCHAR(20);

35.
Python function to fetch records of travellers visiting Jaipur:

python
Copy code
import mysql.connector
def display_jaipur_travellers():
connection = mysql.connector.connect(host='localhost', user='scott',
password='tiger', database='Tours')
cursor = connection.cursor()
query = "SELECT * FROM Travel WHERE Destination = 'Jaipur';"
cursor.execute(query)
for record in cursor.fetchall():
print(record)
connection.close()

SECTION-E
36.
(a) Function to input product data and append it to INVENTORY.DAT:

python
Copy code
import pickle

def append_product():
product = {
"ProductID": int(input("Enter Product ID: ")),
"ProductName": input("Enter Product Name: "),
"Quantity": int(input("Enter Quantity: ")),
"Price": float(input("Enter Price: ")),
"Brand": input("Enter Brand: ")
}
with open("INVENTORY.DAT", "ab") as file:
pickle.dump(product, file)

(b) Function to update the price of Nestle products and reduce by 5%:

python
Copy code
def update_nestle_price():
updated_data = []
with open("INVENTORY.DAT", "rb") as file:
try:
while True:
product = pickle.load(file)
if product["Brand"].lower() == "nestle":
product["Price"] *= 0.95
updated_data.append(product)
except EOFError:
pass

with open("INVENTORY.DAT", "wb") as file:


for item in updated_data:
pickle.dump(item, file)

(c) Function to display products of the brand Nirvana:

python
Copy code
def display_nirvana_products():
with open("INVENTORY.DAT", "rb") as file:
try:
while True:
product = pickle.load(file)
if product["Brand"].lower() == "nirvana":
print(product)
except EOFError:
pass

37.
(a) Cable Layout for Connections:

• Connect Jupiter to Oracle, Oracle to Orbit, and Orbit to Sunrise for efficiency.

Suggested Layout:

rust
Copy code
Jupiter <--> Oracle <--> Orbit <--> Sunrise

(b) Building to house the server:

• Orbit Building: It has the highest number of computers (150), ensuring faster and more
accessible connectivity for the majority of devices.

(c) Placement of Devices:

• Internet Connecting Device/Modem: Place in Orbit Building for optimal


connectivity.
• Switch: Place in each building to connect computers locally.

(d) Type of network to link sales counters:

• MAN (Metropolitan Area Network): Suitable for connecting locations within the same
city efficiently.

(e) Requirement of a repeater:

• A repeater is not required as the longest distance (170 meters) is within the Ethernet
cable range of 100-200 meters.

You might also like