SQP
SQP
SQP-2 :-
Chapter: Python Revision Tour 1
What will the expression print(2**3**2) output? (Ans: 512)
Predict the output of:
python
Copy code
import random
n=random.randint(0,3)
color=[“Y”,”W”,”B”,”R”]
for i in range (1,n):
print(color[i], end="*")
Chapter: Python Revision Tour 2
Which Python approach is used for object serialization in binary files?
(Ans: Pickling)
Write a Python program to create a CSV file containing student data and
another to read data from it.
Chapter: Working with Functions
Write a Python function PushEl(S, element) to add an element into a
stack only if it is divisible by 4. Write another function PopEl(S) to
remove an element from the stack.
Write a Python function EVEN_LIST(L) that returns a list of even numbers
from the list L.
Chapter: File Handling
Explain the difference between 'rb+' and 'wb+' modes in Python file
handling.
Define a function to read and display data from a binary file where
employee records are stored.
Chapter: Data Structure 1
What is the difference between using pop() and remove() in Python lists?
Implement a Python program to push and pop elements from a stack.
Chapter: Data Structure 2
Write a Python function that accepts a list of students with their hostel
names and pushes the details of those living in a specific hostel to a
stack.
Write SQL queries for a given table to retrieve specific data like city-
based filtering or price-based product filtering.
SQP-3 :-
Python Revision Tour 1
1. True/False: “continue” is not a jump statement in a loop.
2. What will the following Python expression output?
python
Copy code
print(2**3**2)
(Ans: 512)
3. Predict the output:
python
Copy code
import random
n=random.randint(0,3)
color=[“Y”,“W”,“B”,“R”]
for i in range(1, n):
print(color[i], end="*")
(Possible Outputs: W, W B*, etc.)**
Python Revision Tour 2
1. Which Python approach is used for object serialization in handling Binary
Files?
o Ans: Pickling
2. Assertion and Reasoning
Assertion (A): A binary file in Python is used to store objects like lists and
dictionaries.
Reasoning (R): Binary files can be read using a text editor like Notepad.
Working with Functions
1. Write a function INDEX_LIST(L) to return the indices of all non-zero
elements in list L.
Example:
Input: [2, 0, 5, 0, 1, 0, 0]
Output: [0, 2, 4]
2. Write a function Count_How_Many(Data, item) to count and display how
many times item is present in the list Data (without using count()).
File Handling
1. Write a function displaywords() to print words from a text file that are
longer than 3 characters.
2. Write a function count_lines() to count and display how many lines in a
file end with 'y' and how many do not.
Data Structure 1
1. Write a function push(stack, data) to push even numbers from a list data
into a stack. Then write pop(stack) to remove the top element of the
stack.
Data Structure 2
1. Write a SQL query to display all records from a table TRAVELS where the
geographical condition is “hilly area” and the distance is less than 1000
KM.
2. Write a Python function Add_New() to accept a record of a player (Player
ID, Name, Runs) and add it to a CSV file playerdata.csv. Also, write
Display_Record() to display records of players with runs greater than
5000 from the CSV file.
SQP-4 :-
Python Revision Tour 1
1. What will the following Python code output?
python
Copy code
LST=[1,2,3,4,5,6]
for i in range(6):
LST[i-1] = LST[i]
print(LST)
2. What will the following expression evaluate to?
python
Copy code
False and bool(15/5*10/2+1)
Python Revision Tour 2
1. Complete the following Python code to create a writer object for a CSV
file emp.csv with a pipe symbol '|' as the delimiter:
python
Copy code
emp_file = ____________
csv_writer = csv.writer(____________)
2. Debug the following code:
python
Copy code
d = dict{}
n = input("enter number of terms")
for i in range(n):
a = input("enter a character")
d[i] = a
Working with Functions
1. Write the output of the following Python code:
python
Copy code
def Change_text(Text):
T = ""
for K in range(len(Text)):
if Text[K].isupper():
T = T + Text[K].lower()
elif K % 2 == 0:
T = T + Text[K].upper()
else:
T = T + T[K-1]
print(T)
Text = "Good go Head"
Change_text(Text)
2. Define the function COUNT_CHAR() to count the occurrences of
arithmetic operators (+, -, *, /) in a file Math.txt.
File Handling
1. Write a function V_COUNT() to read each line from a text file and count
how many lines begin and end with a vowel.
Data Structure 1
1. Write a function DIVI_LIST() that takes a list of numbers and returns two
lists: one with numbers divisible by 2, and the other with numbers
divisible by 5. Example:
python
Copy code
NUM_LST = [2, 4, 6, 10, 15, 12, 20]
D_2 = [2, 4, 6, 10, 12, 20]
D_5 = [10, 15, 20]
Data Structure 2
1. Write a Python program using stack operations to push the names of
students with marks ≥90 from a dictionary and then pop them to display
the names.
SQP-5:-