Answer Key For Pb-Ii
Answer Key For Pb-Ii
SECTION B
22.
(a) Difference between lists and tuples:
(b) emp_records = [
23.
(a) Advantage and disadvantage of Mesh topology:
(b) Expansions:
24.
Errors and corrections in the given code:
Corrected code:
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:
26.
Correct option:
27.
(i) Set Pcode as Primary Key:
28.
Outputs and ranges for variables:
spade$
club$
heart$
OR
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=" ")
OR
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
def Push(Vehicle):
stack = []
if "TATA" in maker.upper():
stack.append(car)
return stack
stack = Push(Vehicle)
SECTION-D
32.
(a) SQL Queries:
OR
Output:
MIN(PRICE): 200, MAX(PRICE): 4300
Output:
KEYBOARD: 2, MOUSE: 3, JOYSTICK: 2
Output:
LASER PRINTER: CANON: 1, KEYBOARD: LOGITECH: 2, MOUSE: LOGITECH: 2, JOYSTICK:
IBALL: 1
33.
(a) Python functions for Winner_details.csv:
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")
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)
sql
Copy code
INSERT INTO FURNITURE (FID, NAME, DATE_OF_PURCHASE, COST, DISCOUNT)
VALUES ('T012', 'Coffee Table', '2022-01-15', 18000, 5);
sql
Copy code
UPDATE FURNITURE SET COST = COST + 1000 WHERE DISCOUNT > 10;
OR
sql
Copy code
DELETE FROM FURNITURE WHERE COST < 20000;
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
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
• Orbit Building: It has the highest number of computers (150), ensuring faster and more
accessible connectivity for the majority of devices.
• MAN (Metropolitan Area Network): Suitable for connecting locations within the same
city efficiently.
• A repeater is not required as the longest distance (170 meters) is within the Ethernet
cable range of 100-200 meters.