
Q121
Q121 Pseudocode:
Define a function that multiplies two numbers and returns the result
Returns sum
Returns product
No return
Syntax error
Q122
Q122 When using with open(file) as f, what does with do?
Ensures file is saved
Automatically closes the file
Opens file in write mode
Reads entire file
Q123
Q123 Identify the error:
file = open('data.txt', 'r');
data = file.read();
file.close()
File not closed properly
Incorrect mode for reading
No error
Error in file.read()
Q124
Q124 In Python, what is the purpose of the try statement?
To test a block of code for errors
To execute code regardless of errors
To generate an error
To declare variables
Q125
Q125 Which exception is raised by Python when a file you try to open does not exist?
FileNotFoundError
IOError
OSError
ValueError
Q126
Q126 When is the else clause in a try-except block executed?
Always after the try block
When no exceptions are raised
When an exception is handled
It is never executed
Q127
Q127 What will be the output of the following code?
try: x = 1 / 0 except ZeroDivisionError:
print("Error")
0
1
Error
No output
Q128
Q128 Pseudocode:
Try to open a file, read its contents;
if file not found,
print error message
File contents are displayed
Error message is printed
No output
File is created and then read
Q129
Q129 What is a list comprehension in Python?
A concise way to create lists
A method to iterate through lists
A type of Python comprehension
A special function for lists
Q130
Q130 What will this list comprehension produce:
[x**2 for x in range(5)]
[0, 1, 2, 3, 4]
[1, 4, 9, 16, 25]
[0, 1, 4, 9, 16]
[1, 2, 3, 4, 5]
Q131
Q131 Pseudocode:
Create a list of lowercase letters from a list of mixed case letters, 'A', 'b', 'C', 'd', 'E'
['A', 'b', 'C', 'd', 'E']
['a', 'b', 'c', 'd', 'e']
['A', 'C', 'E']
['b', 'd']
Q132
Q132 What is a lambda expression in Python?
A one-time anonymous function
A named, reusable function
A loop structure
A data type
Q133
Q133 Pseudocode:
Define a lambda to square a number, use it to get the square of 5
Returns 25
Returns 10
Syntax error
No output
Q134
Q134 Identify the error in this lambda expression:
lambda x, y:
if x > y
return x
else
return y
Incorrect syntax for if-else
Lambda function cannot use conditional
Lambda cannot return values
No error
Q135
Q135 What is a class in Python?
A blueprint for creating objects
A function inside an object
A variable inside an object
A specific object instance
Q136
Q136 In Python, what is 'self' in a class method?
A variable that holds the class name
A reference to the class itself
A reference to the instance that calls the method
A placeholder for future arguments
Q137
Q137 What is polymorphism in the context of object-oriented programming?
Changing the functionality of methods in subclasses
Creating multiple classes that inherit from a single class
The ability of different object types to be accessed through the same interface
Splitting a class into multiple smaller classes
Q138
Q138 Given the class definition:
class Dog:
def init(self, name):
self.name = name,
what does Dog('Buddy').name return?
Dog
name
Buddy
An error occurs
Q139
Q139 Identify the error in this code:
class Animal:
def init(self, name):
name = name
Incorrect use of the constructor
name should be 'self.name'
The class should have more methods
No error
Q140
Q140 Given a class Animal and a subclass Dog, which method demonstrates polymorphism?
Animal.speak() and Dog.speak() have different implementations
Dog has the same attributes as Animal
Dog uses a method from Animal without changing it
Animal has a method not present in Dog
Q141
Q141 Identify the issue in this inheritance scenario:
class Bird(Animal):
def fly(self):
pass, class Penguin(Bird):
def fly(self):
print("Can't fly")
Birds don't have a 'fly' method by default
Penguins shouldn't inherit from 'Bird'
fly' method in 'Penguin' contradicts 'Bird'
No issue present
Q142
Q142 What is a decorator in Python?
A function that modifies the functionality of another function
A function that creates new functions
A syntax for defining anonymous functions
A tool for debugging functions
Q143
Q143 What is a generator in Python?
A type of collection
A tool for creating iterators
A function that returns a single value
A module
Q144
Q144 What is a regular expression used for in Python?
Error handling
Data serialization
Pattern matching and text manipulation
Memory management
Q145
Q145 What is JSON primarily used for in Python?
Web development
Data serialization and communication between different systems
Numeric computations
File compression
Q146
Q146 When working with Excel files in Python, which library is commonly used to read and write .xlsx files?
Pandas
Numpy
OpenPyXL
CSV
Q147
Q147 Identify the error in this code for reading a CSV file:
import csv;
reader = csv.reader(open('file.csv', 'wb'))
The file mode should be 'rb', not 'wb'
csv.reader does not take a file object
The file 'file.csv' does not exist
Incorrect use of the csv module
Q148
Q148 How does the os.path.join() function benefit file path construction?
Increases file access speed
Ensures correct path format for the operating system
Encrypts the file path
Splits the file path into components
Q149
Q149 Identify the error in this code:
import os;
os.rmdir('mydir') assuming 'mydir' contains files and subfolders.
Incorrect module imported
os.rmdir() cannot delete non-empty directories
Wrong syntax for removing directories
No error
Q150
Q150 Why is PEP 8 important in Python development?
It provides guidelines for error handling
It outlines the standard coding conventions
It defines the core functionality of Python
It lists Python's reserved words

