0% found this document useful (0 votes)
9 views8 pages

SQP

The document contains a series of sample questions and programming tasks related to Python, covering topics such as functions, file handling, and data structures. It includes code snippets, multiple-choice questions, and programming exercises designed to test knowledge and skills in Python programming. Each section is organized by topic and includes specific questions or tasks for students to complete.

Uploaded by

tdew45143
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

SQP

The document contains a series of sample questions and programming tasks related to Python, covering topics such as functions, file handling, and data structures. It includes code snippets, multiple-choice questions, and programming exercises designed to test knowledge and skills in Python programming. Each section is organized by topic and includes specific questions or tasks for students to complete.

Uploaded by

tdew45143
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

SQP-1 :-

Python Revision Tour 1 & 2:


1. What will be the output of the following Python Code?
python
Copy code
tp=5
tp1=tp * 2
print(len(tp1))
Options:
a) 0
b) 2
c) 1
d) Error(SAMPLE-QP-1)
2. Which of the following are valid strings in Python?
a) This is a string
b) {This is a string}
c) (This is a string)
d) “This is a string”(SAMPLE-QP-1)
3. Fill in the blank: The first line of a function definition is called _______.(SAMPLE-QP-
1)
4. By default, Python names the segment with top-level statements (main program)
as _______.(SAMPLE-QP-1)
Working with Functions:
1. What is the output of the following snippet?
python
Copy code
def fun(n):
if n > 100:
return n – 5
return fun(fun(n+11))
print(fun(45))
Options:
a) 50
b) 100
c) 74
d) Infinite loop(SAMPLE-QP-1)
2. Assertion Reasoning Question:
Assertion (A): A user-defined function that accepts 3 parameters where no
parameter carries a default value must be called with 3 parameters.
Reason (R): Since there are no defaults, 3 parameters must be passed to the function.
Options:
a) Both A and R are true and R is the correct explanation
b) Both A and R are true but R is not the correct explanation
c) A is true but R is false
d) A is false but R is true(SAMPLE-QP-1)
File Handling:
1. Which of the following functions will read lines of a text file as list elements?
a) read()
b) get()
c) readline()
d) readlines()(SAMPLE-QP-1)
2. Write a program to accept a filename and a position. Using the inputs, call a
function SearchFile(Fname, pos) to read the contents of the file from the position
to the end. Now, display all those words that start with “U” or “u”.(SAMPLE-QP-1)
Data Structures 1 & 2:
1. Write a user-defined function to accept a string and check whether it is a
palindrome or not.
(A palindrome is a string that is the same as its reverse)(SAMPLE-QP-1)
2. Predict the output of the Python code given below:
python
Copy code
x=[1,2,3,4]
counter=0
while counter < len(x):
print(x[counter]*'$')
for y in x:
print(y*'*')
counter += 1

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:-

You might also like