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

HP II Answer

The document contains a series of questions and answers related to computer science concepts, covering topics such as data structures, programming, networking, and SQL queries. It includes sections with multiple-choice questions, explanations of programming logic, and differences between various technologies. Additionally, it provides code snippets for file handling and data manipulation using Python.

Uploaded by

afrayasmin2302
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)
22 views12 pages

HP II Answer

The document contains a series of questions and answers related to computer science concepts, covering topics such as data structures, programming, networking, and SQL queries. It includes sections with multiple-choice questions, explanations of programming logic, and differences between various technologies. Additionally, it provides code snippets for file handling and data manipulation using Python.

Uploaded by

afrayasmin2302
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

SECTION – A (1 mark each)

1. True
2. (c) _data
3. (c) {1: "One", 3: "Three"}
4. (a) 10, 5
5. (c) ['C','O','M','P','U','T','E','R']
6. (b) seek()
7. (c) IndexError
8. (b) Email service
9. (c) Statement 3
10. (b) 2
11. (c) both iii and iv
12. (d) All of the mentioned
13. 1200 baud
Calculation:
Baud rate = bit rate / bits per symbol = 2400 / 2 = 1200
14. (d) –8.0
6*3 = 18
4**2 =16
18/16 =1.125
1.125//5 =0.0
0.0 - 8 = –8.0
15. (d) Cartesian Product
16. 1
min(True,5,-2) → min(1,5,-2) = -2
max(-2, -3, 1) = 1
17. (c) 1000 bps
Bit rate = baud rate × bits per symbol = 500 × 2 = 1000
18. 20 MHz increase → New bandwidth = 40 – 20 = 20 MHz
19. (d) 3 + [Link](4)
randrange(4) → 0,1,2,3
→ 3 to 6
20. (b)
Both A and R are true but R is NOT the correct explanation.
21. (a)
Both A and R true, and R explains A.
SECTION – B
22. (A) Write two points of difference between Bridge and Gateway
Bridge Gateway
1. Works at Data Link Layer (Layer 2) 1. Works at Network Layer and above
of OSI model. (Layer 3–7).
2. Connects similar networks (same 2. Connects different networks
protocols). (different protocols).

(OR)

Difference between Circuit Switching and Packet Switching


Circuit Switching Packet Switching
1. A dedicated communication path is 1. No dedicated path; data is sent in
established before data transfer. packets independently.
2. Suitable for data transfer; delay
2. Suitable for voice calls; delay is low.
may vary.

23. Understanding the loop


• ANIMALS list indices:
Index Value
0 CAT
1 DOG
2 LION
3 TIGER
4 BEAR
• N = [Link](1,4)
So possible values of N: 1, 2, 3, 4.
The loop
for i in range(4, N, -1):
Means:
• Start at i = 4
• Go down to N + 1
• Step -1
So the values taken by i depend on N.

CASEWISE OUTPUT
CASE 1 → N = 1
range(4,1,-1) → i = 4,3,2
OUT = ANIMALS[4] + ANIMALS[3] + ANIMALS[2]
→ "BEAR" + "TIGER" + "LION"
Output: BEARTIGERLION

CASE 2 → N = 2
range(4,2,-1) → i = 4,3
OUT = "BEAR" + "TIGER"
Output: BEARTIGER

CASE 3 → N = 3
range(4,3,-1) → i = 4
OUT = "BEAR"
Output: BEAR

CASE 4 → N = 4
range(4,4,-1) → No values (empty loop)
OUT = ""
Output: (blank line)

Final Answer
Possible correct outputs are:
(i) BEARTIGERLION
(ii) BEARTIGER
(iii) BEAR

24. Step-by-step explanation


String:
Index positions:
Index Letter
0 P
1 Y
2 T
3 H
4 O
5 N
6 P
7 R
8 O
Index Letter
9 G
10 R
Slice: s[Link]
• Start at index 2 → T
• Go up to index 9 (10 excluded)
• Step by 2
So indices selected:
2, 4, 6, 8
Letters:
2→T
4→O
6→P
8→O
So output = "TOPO"

25. def count_e_words():


count = 0
with open("[Link]", "r") as f:
for line in f:
words = [Link]()
for w in words:
if [Link]('e'):
count += 1
print("Number of words ending with 'e':", count)

26. try:
a = int(input("Enter numerator: "))
b = int(input("Enter denominator: "))
result = a / b
print("Result =", result)
except ArithmeticError:
print("Arithmetic Error occurred (possibly division by zero).")

27. (c) [] [25, 5, 20, 10, 15]


28. Let’s index the string:
0#
1#
2P
3y
4t
5h
6o
7n
8
9S
10 l
11 i
12 c
13 i
14 n
15 g
16 #
17 #
Slice: str2[1::3]
Start at index 1 → #
Step = 3
Indices selected:
1, 4, 7, 10, 13, 16
Characters:
1→#
4→t
7→n
10 → l
13 → i
16 → #
✔ Output:
#tnli#

b. dict_items([('brand', 'Tata'), ('year', 2023), ('model', 'Nexon')])

SECTION -C

List indexing
Index : Value
0 :5
1 : 12
2 :7
3 : 25
4 : 30
5 : 18
6 : 40

Loop
range(6, 0, -2) generates:
i = 6, 4, 2
We evaluate each iteration:

Iteration 1: i = 6
L[6] = 40 → even
So use:
x = x + str(L[i-1]) + "*"
L[5] = 18
x = "18*"

Iteration 2: i = 4
L[4] = 30 → even
So:
x = x + str(L[3]) + "*"
L[3] = 25
x = "18*25*"

Iteration 3: i = 2
L[2] = 7 → odd
So:
x = x + str(L[2]) + "@"
x = "18*25*7@"

Final Output
18*25*7@

30. a) def countwords():


count = 0
with open("[Link]", "r") as f:
for line in f:
words = [Link]()
for w in words:
if any([Link]() for ch in w): # check if any digit exists
count += 1
print(count)

or

b) def countwords():
with open("[Link]", "r") as f:
text = [Link]()

count_is = [Link]("is")
count_are = [Link]("are")

print("No. of words 'is':", count_is)


print("No. of words 'are':", count_are)

31. i) Count customers per city:


• DELHI → Deepak, Mohan, Sahil, Sonal, Arun → 5 customers
• MUMBAI → Rohan, Neha → 2 customers
✔ Correct Output
CITY COUNT(*)
DELHI 5
MUMBAI 2

ii) SELECT MIN(QTY), MAX(QTY) FROM CUSTOMER;


Customer QTY values:
20, 10, 5, 3, 7, 5, 15
• Minimum QTY = 3
• Maximum QTY = 20
✔ Output:
MIN(QTY) MAX(QTY)
3 20

iii. SELECT [Link], PRODUCTNAME FROM CUSTOMER,


COMPANY WHERE [Link] = [Link] AND
PRODUCTNAME = 'LAPTOP';
Step 1 → Identify PRODUCTNAME = 'LAPTOP'
From COMPANY table:
CID PRODUCTNAME
666 LAPTOP
Step 2 → Customers who purchased CID 666:
NAME CID QTY
Deepak Kumar 666 10
Arun Singh 666 15
✔ Output
CNAME PRODUCTNAME
DEEPAK KUMAR LAPTOP
ARUN SINGH LAPTOP
32. import csv

def display_items():
count_price = 0 # to count items with Price > 50000

with open("[Link]", "r") as f:


reader = [Link](f)
next(reader) # skip header line

print("Details of all Laptops:")

for row in reader:


code, item, brand, price, qty = row
price = int(price)

# Part (i): Display all Laptops


if item == "Laptop":
print(row)

# Part (ii): Count records with price > 50000


if price > 50000:
count_price += 1

print("\nNumber of items with Price > 50000:", count_price)

34. i. Query to show Teacher, Subject, Gender, and Designation (using


CODE)
SELECT [Link], [Link], [Link], [Link]
FROM SCHOOL S, ADMIN A
WHERE [Link] = [Link];

ii. Retrieve teachers whose PERIODS > 25

SELECT [Link], [Link], [Link]


FROM SCHOOL S, ADMIN A
WHERE [Link] = [Link] AND [Link] > 25;

iii. Display each teacher’s name, subject, and the designation of another
teacher who shares the same gender

SELECT [Link] AS Teacher,


[Link] AS Subject,
[Link] AS Another_Teacher_Designation
FROM SCHOOL S1, ADMIN A1, SCHOOL S2, ADMIN A2
WHERE [Link] = [Link]
AND [Link] = [Link]
AND [Link] = [Link]
AND [Link] <> [Link];

iv. SQL to fetch teacher’s name, subject, and designation where CODE
matches

SELECT [Link], [Link], [Link]


FROM SCHOOL S, ADMIN A
WHERE [Link] = [Link];

v. Show each teacher’s name & experience along with the name of another
teacher who has MORE experience

SELECT [Link] AS Teacher,


[Link] AS Experience,
[Link] AS More_Experienced_Teacher
FROM SCHOOL S1, SCHOOL S2
WHERE [Link] > [Link];
35. import csv

# --------------------------
# PART 1: CREATE CSV & WRITE 10 RECORDS
# --------------------------

with open("[Link]", "w", newline="") as file:


writer = [Link](file)

# Writing header
[Link](["Dvdid", "Dvd_Name", "Qty", "Price"])

# Writing 10 sample records


data = [
["D01", "Avengers", 10, 30],
["D02", "Lion King", 12, 20],
["D03", "Harry Potter", 8, 40],
["D04", "Frozen", 15, 22],
["D05", "Avatar", 6, 50],
["D06", "Toy Story", 9, 18],
["D07", "Spiderman", 7, 35],
["D08", "Inception", 5, 28],
["D09", "Batman", 11, 24],
["D10", "Iron Man", 14, 45]
]

[Link](data)

print("[Link] file created successfully.\n")

# --------------------------
# PART 2: DISPLAY DVDs WHERE PRICE > 25
# --------------------------

print("DVDs with price > 25:\n")

with open("[Link]", "r") as file:


reader = [Link](file)
next(reader) # Skip header

for row in reader:


price = int(row[3])
if price > 25:
print(row)

37. i) import pickle

def MakeFile():
# Open file in append-binary mode
file = open("[Link]", "ab")

# Input item details


itemid = input("Enter Item ID: ")
name = input("Enter Item Name: ")
qty = int(input("Enter Quantity: "))
price = float(input("Enter Price: "))

# Store as list/record
record = [itemid, name, qty, price]

# Dump record into binary file


[Link](record, file)
[Link]()

print("Record added successfully!")

ii) import pickle

def CountRec():
count = 0
try:
file = open("[Link]", "rb")
print("Employees earning more than 20000:\n")

while True:
record = [Link](file)
empid, name, salary = record

if salary > 20000:


print(record)
count += 1

except EOFError:
[Link]()
print("\nTotal employees with salary > 20000:", count)

35. ) Install the server in the block having the maximum number of
computers, because it reduces traffic and ensures faster access.
ii) Use Star Topology (or Tree Topology) for wired connectivity.
iii) Install a Switch in each block to interconnect all computers efficiently.
iv) Place a Repeater on the longest cable segment (distance > 100m) to
regenerate weak signals.
v) A WAN will be formed because the distance (1250 km) is very long and
connects different cities.

You might also like