0% found this document useful (0 votes)
5 views5 pages

Python and SQL Concepts Explained

The document contains a series of answers to sample questions related to Python programming, SQL, and computer science concepts. It covers topics such as data types, error handling, file handling, and network protocols, providing explanations and examples for various programming scenarios. The answers are structured in a way that reflects understanding of both theoretical concepts and practical applications.

Uploaded by

psk78896
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)
5 views5 pages

Python and SQL Concepts Explained

The document contains a series of answers to sample questions related to Python programming, SQL, and computer science concepts. It covers topics such as data types, error handling, file handling, and network protocols, providing explanations and examples for various programming scenarios. The answers are structured in a way that reflects understanding of both theoretical concepts and practical applications.

Uploaded by

psk78896
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

A N S W E R S

Sample Question
Paper-2
11. (b) False
SECTION - A Why? "False" is a non-empty string ’ bool("False")
= True ’ True == False ’ False

1. (c) 2 Concept: Python Data Types - Boolean, Truthy/


x[7-5] ’ x(2] ’ 2
Why? x[1] is 7, so Falsy values
Concept: Python Lists Indexing, Arithmetic
12. (b) (0, 2, 3]
Why? b is an alias of a, so modifying b[0] changes
expressions

Returns employees with salary from 20,000 a(0]


2. (c) R Reference
t o50,000 Concept: Python Lists Mutable objects,
Why?
BETWEEN is inclusive; returns rows where assignment
and s 50000
calary is 2 20000 13. (a) True
BETWEEN clauSe True
Concept: SQL - WHERE, Why? type(l) is list ’ so type(l|) == list is
3. (a) pivL
Concept: Python Data Types - Type checking
every second
Why? s[:-2] reverses string and picks 14. (c) pop)
character ’p,T,
'v, L' element
Traversal Why? pop() removes and returns the last
Concept Python Strings - Slicing, from the list.
4. (a) DELETE Concept: Python Lists - pop) method
retains the
Whv? DELETE removes records but 15. (b) TCP
the table
structure; DROP removes
(DROP) Why? TCP provides reliable, connection-oriented
Concept: SQL - DML (DELETE), DDL communication; IP is unreliable packet delivery.
5. (a) 90 Concept: Computer Networks - Protocols (TCP/P)
Why? marks[C] = 85 + 5 =90 16. (a) 2
Key-Value
Concept: Python Dictionary - Methods, Why? x**y = 8,8 //3 = 2, but this looks like 2 ** 3
manipulation 1/3’8/l3’2
6. (b) ALTER TABLE Concept: Python Operators- Exponentiation, Floor
division
Why? ALTER TABLE modifies the structure (e.g.,
add a column). 17. (c) To filter records
Concept: SQL DDL ALTER TABLE (schema Why? WHERE is used to filter rows based on a
modification) condition.

1. (b) 8.2] Concept: SQL - Filtering records with WHERE


Why? pop(l) removes element at index 1’ [8, 2) 18. (c) Zero DivisionError
Concept: Python Lists - pop) method Why? The Division by zero always raises a
ZeroDivisionError in Python.
8. (d) ORDER BY
Why? ORDER BY Sorts the result set in ascending
Concept: Python Exception Handling
ZeroDivisionError
or descending order.
Concept: SQL - Sorting results (ORDER BY) 19. (a) id)
9. (a) 192 168 0.256 Why? id)returns the unique memory address of
an object.
Why? Each octet must be in the range 0-255, here Concept: Python Built-in Functions - id) memory
256 is invalid.
address
Concept: Computer Networks IP Addressing
(IPv4) 20. (c) A is true but R
is false
10. (a) thonRo Why? trv block handles riskv code; finally executes
regardless of an exception.
Why? msg[2:8] h,o,n', R,o - thonRo' Concept: Python Exception Handling - try,
finally
Concept Python Strings - Indexing, Slicing
SCIENCE, Class-12
OSWAAL CBSE Sample Ouestion Papers, COMPUTER
120|
tell()
21. (c) A is true but R is false. 1. Returns the current byte offset
one PRIMARY KEY, so
Why? A table can have only
R is incorrect. 2.
Cursor.

Useful to save the


(posiion) ot the F
current position
Key constraints)
Concept: SQL - Keys (Primary seek) back to it later.
Concept: File Handling --seek),
SECTION - B tell) /
OR
Error types
(b) There can be many, a few are:
22. (a) seek(offset, whence=0) 1. Using an undefined variable
byte position specified by print(x) # x is not defined - -
1. Moves the file cursor to a
offset. =
2. Incorrect indentation NarneError
point: 0 = start, 1 def greet():
2. whence controls reference
position, 2 = end. Returns
the new absolute print("Hi) #IndentationError
current
implementations.
position in many
23. Corrected Code:
def reverse_vowels(word):
vowels = 'aeiouAEIOU'
to
vOW = || # Correction 1: Changed from vOW = 0 voW = | Logical
Wrong data type) Eror.
for c in word:
if cin vowels: # Correction 2: Added missing colon (Syntax Error)
[Link](c) # Correction 3: Now works
because vow is alist
(Logical Error in
original)
result =
for c in word:
if c in vowels: # Correction 4: Changed from '== to 'in' (Logical Error:
WIOng
comparison)
result += [Link])
else:
result += C
return result
Concept: Python Functions, String handling, Error correction

24. (a) Output: 26. Output: [5, 8, 9, 1, 3, 7]


[Let's make learn', 'g fun and', 'teractive'] Concept: Python Functions List Traversal &
-1 Comparison
OR
27. (a)
(b) #I. [Link]("a") (1) WHERE Clause
# II. [Link](2, "orange") (II) DELETE FROM Logs;
Concept: Python Strings -split), find) / Lists OR
insert) (b) In MySQL, ALTER is used to change the table's
25. (a) def delete student(students, name): structure, such as adding, modifying or removing
if name in students: columns, while UPDATE is used to change the
actual data stored in the table.
[Link](name)
else: For example: This command adds a new column
named "email" to the "custonmers" table ALTER
print("Student not found") TABLE customers ADD email VARCHAR(255);
OR
Whereas:
(b) def add grade(grade_book, student, grade): UPDATE customers SET email = 'abc@example.
if student not in grade_book: com' WHERE customer id = 3;
grade_ book[student] =grade The above command updates the "email" value to
else: abc@[Link]' for the customer with ID 3.
print("Grade already added") Concept: SQL - WHERE, DELETE,
UPDATE,
Concept: Python Functions - Lists, Dictionaries ALTER
Answers 127

28.(a)
Router:A,
device that coonnects multiple networks
data packets to their correct
SECTION -D
L
32. (a)
f o r w a r d s

and
destinations.

connects and filters traffic i. SELECT Event, SUM (Ticket)


A device that FROM EventReg
1L.
Bridge:

different LAN segments to improve GROUP BYEvent HAVING SUM(Tickets) >= 2;


ii. SELECT FROM EventReg ORDER BY
between

performance.
fee DESC;
Computer Networkss- Devices, Switching iüi. SELECT Event FROM
Concept: EventReg WHERE
Techniques
Participant IN (Mira', 'Priya');
OR iv. SELECT Event, SUM(Fee) FROM EventReg
GROUP BY Event;
b World Wide Web Consortium, FTP - File OR
W3C:
LTransfer Protocol. (b) i.
[Link]: Acommunication method where Event SUM(Tickets) |
dedicated path is set up between the sender and
IL. +
receiver before data transfer and kept active for the Hackathon | 3|
entire session, often used in telephone networks.
Seminar NULL |
|Workshop | 3|
SECTION -C + +
ii. +--.

29. la) import csv | RegiD | Participant | Event Tickets | Fee


def show_funded): +.

with open('[Link]", newline=") 501 Mira | Workshop | 2 500.00


as f: |503| Priya | Workshop| 1|500.00 |
reader = [Link](f) +--+. -+

for row in reader: iüi, +-_+


if float(row["Funding']) >= 50: |ReglD | Event|
print(row["Startup") +------t

OR | 501 | Workshop
b) def search_innovate): | 502 | Hackathon |
with open("Pitchldeas. txt") as f: | 503 | Workshop|
for line in f: 504 Seminar
if "innovate" in [Link]): | 505 | Hackathon|
print([Link] ) iv. + t
Concept: File Handling - CSV && Text Files
|MIN(Fee)|
30. def push_discharge(DischargeStack, record): +
[Link](record) | 300.00|
print(Record Added") +--
def pop_discharge(DischageStack): Concept: SQL - Aggregates, GROUP BY, Filtering,
if not DischargeStack.: LIKE, MIN
print(Empty Stack") 33. import csv
retum None
I. AddSale) - Accept a sales record and append
record =[Link]) [Link]
print("Record removed:", record) def AddSale):
returm record Book_ID = input("Enter Book ID: ")
Concept: Data Structures - Stack implementation Book Title = input("Enter Book Title:
")
using List Copies_Sold = int(input('Enter Copies Sold:
31, (a) Output: a7,k2,e5 Price_Per_Copy = float(input("Enter Price
per
OR
b) Output: 11|5|17 Copy: "))
("[Link]", "a", newline-") as
Concept: Python - Dictionaries, Iteration, String with open(
join f:
128 OSWAAL CBSE SAmple Ouestion Papers, COMPUTER SCIENCE, Class- 12

writer = [Link]()
writer writerow([Book_ID, Book_Title, SECTION -E
Copies_Sold, Price_Per_Copy|) 36. import pickle
print("Record added successfully. ") def append_subscriber):
Calculate total
I. CalculateTotal Revenue) with open("[Link]",
revenue "ab") as f:
SubscriberlD =int(input("ID
def CalculateTotalRevenue): Name = input('Name: ") "
total = 0 MonthsSubscribed =
with open("[Link]", newline-") as f: intinput "
PlanType =input('PlanType:
reader = [Link](f)
[Link]((SubscriberlD. NarmeAonths.
for row in reader:
# Assumes file has no header
MonthsSubscribed, PlanTypel
def upgrade_premium):
total += int(row(2) float(row[3) subs = |
retum total with open("[Link]", "rb") as f
Concept: File Handling - CSV Fles (writer, reader) try:
34. i. SELECT Name FROM Customer c JOIN while True:
Apparel a ON [Link] = [Link] WHERE [Link] rec =[Link](f)
BETWEEN 500 AND 2000; if rec(2] >= 12:
ii. SELECT cName, [Link], [Link], [Link] FROM rec[3] ="Premium"
Customer cJOIN Apparel a ON [Link]= [Link];
iii. SELECT [Link] FROM Customer C except:
[Link](rec)
JoIN Apparel a ON [Link] = [Link] WHERE pass
cName=Tanya'; with open("'[Link]", "wb") asf
iv. (a) ALTER TABLE Customer MODIFY City for r in subs:
VARCHAR(40); [Link](r, )
OR Concept: File Handing - Binary
(b) Cross Join: module) Files (picd
SELECT FROM Apparel, Customer; 37. i. ADMIN - As it
has the
Concept: SQL- Joins, Alter Table, Cross Join computers (110)which will keephighest number of
maximum
35. import [Link] local to the server. trafic
def RestockAndShow): ii. Use star topology with ADMIN
at centre
db = [Link]. Star
connect(host="localhost", user="root", Topology
passwd='store", database-"Stores DB") Food
Decorators
cur = [Link])
iid = int(input("Enter itemID: ")
qty = int(input('Enter quantity to restock: ")
[Link]("UPDATE WarehouseStock SET Admin Media
available = available + %s WHERE
itemID =
%s", (qty. id)
iii. Use Switch in each building
[Link]) iv. c. Video Conferencing
[Link]"SELECT FROM
WarehouseStock WHERE available > 12") V. (a) WAN - connects Mumbai to Delhi
for row in [Link]): OR
a filter trafic
print(row) (b) Bridge-A bridge is used to connecttand helpíng

[Link]) between two similar network segments

improving

them work as a single network and


Concept: Python-SQL Connectivity performance.
execute, commit) (connect, Topolog
Concept: Computer Networks Types
Devices, Transmission Media, Network
Answers 129

UPGRADE YOUR ANSWER

Differentiate between seek) and tell) functions in Python.


Q22 Q
CommonlyMade Errors:

Students write only definitions without explaining syntax or use.


Forgetto
the whence parameter in seek).
mention
when the question is for 3or 4 marks.
Do not provide an example
Answering Tips:
Write dear definitions with keywords (file pointer, offset, whence, byte position).
code and use-case.
Eor 34 marks, add example
Example):
i3Marks (Definition + (0=start, 1=current, 2=end).
ookiofset,whence=0): Moves pointer to desired location
pointer.
tell0: Returns current position of the file
Example:
f= open([Link]",")

print([Link](0) #0
; fread(5)
print([Link](0) #5
fseek(0)
print([Link]) #0
fcose()

You might also like