End Module A Mock Questions
End Module A Mock Questions
a) int
b) str
c) list
d) bool
a) hellohellohello
b) hello hello hello
c) hellohello hello
d) hello hellohello
a = [1, 2, 3]
b = a
b.append(4)
print(a)
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4]
d) Error
5. Which loop is better suited for processing a fixed number of items in a shopping cart?
a) for loop
b) while loop
c) do-while loop
d) Infinite loop
6. When a function that processes a payment doesn’t specify a return statement, what value
does it return by default?
a) 0
b) None
c) False
d) Empty string
try:
print(5 / 0)
except ZeroDivisionError:
print("Error")
a) 0
b) None
c) Error
d) ZeroDivisionError
8. If a function opens a log file to record new data, which mode will erase any existing
content in the file when opened?
a) r
b) w
c) a
d) r+
9. When loading a customer order file, which method reads the entire file content into a
single string?
a) read()
b) readline()
c) readlines()
d) write()
10. In a product inventory system, which data structure allows storing duplicate product
names when the same item is stocked in multiple locations?
a) Set
b) List
c) String
d) Tuple
11. In a customer queue system, which function is used to add a new customer to the end of
the waiting list?
a) write()
b) add()
c) append()
d) extend()
12. In which of the following situations would you use the elimination method to solve
simultaneous equations?
a) When the equations are linear
b) When the equations are non-linear
c) When the equations are inconsistent
d) When you need to find the determinant
13. In a list of customer IDs, which search algorithm would divide the list in half at each step to
quickly locate a specific ID?
a) Linear Search
b) Bubble Sort
c) Binary Search
d) Merge Sort
14. In a record-keeping system where employee IDs should not change, which of the following
data structures is immutable?
a) List
b) Dictionary
c) Set
d) Tuple
15. In a classroom, a teacher records the test scores of 30 students across 4 subjects: Math,
Science, English, and History. If each student's scores are arranged in a table with each
row representing a student and each column representing a subject, what are the
dimensions of this table?
a) 30 x 3
b) 30 x 4
c) 4 x 30
d) 4 x 40
17. A data analyst is given a dataset in matrix form where each row represents a unique city
and each column represents a different environmental metric, such as temperature,
humidity, and air quality index. To analyze trends across metrics rather than cities, the
analyst decides to swap the rows and columns of the matrix. Which matrix operation
would the analyst perform?
a) Transpose
b) Inverse
c) Determinant
d) Trace
lst = [1, 2, 3]
lst[1] = 5
print(lst)
a) [1, 5, 3]
b) [1, 2, 5]
c) [5, 2, 3]
d) Error
21. In a recent survey, a teacher collected the test scores of her 30 students to evaluate their
overall performance. Which statistical measure would she use to represent the average
value of these test scores?
a) Mean
b) Median
c) Mode
d) Range
22. In a quality control process, a manufacturer records the heights of a sample of 1,000
products. Upon plotting the distribution of these heights, the manager notices that it forms
a symmetric bell-shaped curve. Which type of distribution does this bell shape represent?
a) Uniform distribution
b) Normal distribution
c) Poisson distribution
d) Binomial distribution
23. A marketing analyst is reviewing a dataset containing customer purchase histories. They
need to find out which customers made purchases exceeding $500. Which Python library
is best suited for this data manipulation task?
a) Math
b) Pandas
c) SciPy
d) Seaborn
24. A data analyst wants to import a CSV file containing sales data into their Python
environment for analysis. Which function from the Pandas library should they use to read
the CSV file??
a) read_file()
b) read_csv()
c) read_data()
d) load_csv()
27. In a data visualisation project analysing monthly temperature changes, how do you create
a line plot using Matplotlib?
a) plot()
b) line()
c) scatter()
d) draw()
1 2 5 6
28. What is the result of 2A + 3B if A =[ ] and B = [ ]?
3 4 7 8
17 22
a) [ ]
27 32
16 22
b) [ ]
27 32
17 23
c) [ ]
27 32
17 10
d) [ ]
27 32
29. A data analyst is working on a project that involves analyzing temperature data from
different cities. To store the temperature readings in a structured way, they decide to use
NumPy. Which function should they use to create a NumPy array for storing these
temperature readings??
a) np.create_array()
b) np.array()
c) np.new_array()
d) np.initialize_array()
30. How many times will "Python" be printed by the following code?
32. A software developer needs to log user activity in an application. They decide to open a log
file in append mode to add new entries while also being able to read the existing entries. If
they open the file using the mode 'a+', what operations can they perform regarding reading
and writing in the log file??
a) Only write operations
b) Only read operations
c) Both read and write operations
d) No operations
def func(x):
return x**2
print(func(3))
a) 6
b) 9
c) 3
d) 0
38. If a list has 5 elements and you insert a new element at index 3, how many elements will
the list contain after the operation?
39. What is the determinant of the following 2x2 matrix?
4 3
( )
2 1
import numpy as np
a = np.array([1, 2, 3, 4])
print(a.sum())
x = 10
y = 5
print(x // y)
a) 2
b) 2.0
c) 1
d) 0
45. If a file named "data.txt" contains 3 lines, how many lines will it contain after adding 2
more using append mode?
46. Which of the following are valid file modes in Python? Select all that apply.
a) r+
b) a
c) write
d) w+
49. Which sorting algorithm has the best time complexity for sorted data?
a) Bubble Sort
b) Quick Sort
c) Insertion Sort
d) Merge Sort
51. Which of the following operations are valid on matrices? Select all that apply.
a) Matrix addition
b) Matrix division
c) Matrix multiplication
d) Transposition
fig, ax = plt.subplots(2, 2)
np.array([1, 2, 3]) * 2
57. Which function from the NumPy library creates an array filled with zeros?
a) np.ones()
b) np.zeros()
c) np.empty()
d) np.fill()
b) c1 b − c2 a
c) a ⋅ b
d) None of the above
b) (3, 3)
c) (2, 0)
d) (0, 2)
64. Which of the following are valid ways to create a list in Python? Select all that apply.
a) list1 = []
b) list2 = list()
c) list3 = [1, 2, 3]
d) list4 = (1, 2, 3)
65. Which of the following methods can be used to add elements to a list in Python? Select all
that apply.
a) list.append()
b) list.add()
c) list.insert()
d) list.extend()
66. Which of the following are valid ways to define a function in Python? Select all that apply.
a) def function_name():
b) function_name() = def
c) def function_name(param):
d) function_name(param) =>
b) (x, y) = (4, 2)
c) (x, y) = (2, 4)
d) (x, y) = (0, 0)
68. What is the linear combination of the vectors u = (2, 3) and v = (1, 4) with coefficients 3
and 2 respectively?
a) (8, 17)
b) (8, 8)
c) (17, 17)
d) (1, 9)
1 2
[ ]
3 4
71. Given a sorted array of size n=16, how many comparisons are made in the worst-case scenario
when using the binary search algorithm to find a target value?
a) 2
b) 4
c) 5
d) 8
72. What will be the output of the following Python code snippet?
even_numbers = [x for x in range(20) if x % 2 == 0] print("Even numbers:", even_numbers)
a) Even numbers: [1, 3, 5, 7, 9]
b) Even numbers: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
c) Even numbers: [0, 1, 2, 3, 4]
d) Even numbers: [2, 4, 6, 8, 10]
73. What is the range of the dataset: 18, 21, 15, 22, 25?
x = func(1)
y = func(2, [])
z = func(3)
print(x, y, z)
75. Given a DataFrame df with a column Age , what command would filter rows where Age is
greater than 30?
a) df.Age > 30
b) df['Age'] >= 30
c) df[df['Age'] > 30]
77. Calculate the dot product of the vectors u = (3, 5) and v = (2, 4).
78. Which of the following will sort a dictionary d by its values in ascending order?
a) sorted(d.keys())
b) sorted(d.items(), key=lambda x: x[1])
c) sorted(d.values())
d) sorted(d, key=lambda x: x[0])
3 6 9
[3, 1, 4, 2]
After performing one pass of the insertion sort algorithm (in ascending order), what will the list
look like?
a) [1, 3, 4, 2]
b) [3, 1, 2, 4]
c) [1, 2, 3, 4]
d) [1, 4, 2, 3]
try:
num = int("abc")
print(num)
except ValueError:
print("There was an error in converting the string to an integer.")
a) abc
b) There was an error in converting the string to an integer.
c) None
d) 0
82. How many points will be plotted by the following code?
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 11)
y = x**2
plt.plot(x, y)
plt.show()
a) 10
b) 11
c) 12
d) 13
a = 10
b = 5
if a > b and b != 0:
print("Condition met")
else:
print("Condition not met")
a) Condition met
b) Condition not met
c) Error
d) No output
84. What will be the final value of x after the following loop executes?
x = 0
for i in range(1, 6):
if i % 2 == 0:
x += i
else:
x -= i
a) -3
b) -1
c) 1
d) 3
x = 2
y = 3
for i in range(4):
x *= y
y += 1
print(x)
a) 36
b) 144
c) 216
d) 720
result = 0
for i in range(1, 6):
for j in range(1, i+1):
result += j * i
print(result)
a) 70
b) 85
c) 140
d) 120
87. Given two vectors A = [3, 4] and B = [1, 2], what is the result of their dot product A ⋅
B?
a) 7
b) 8
c) 11
d) 10
2 3 5
88. If matrix M =[ ] and vector V = [ ], what is the result of the matrix-vector
1 4 6
multiplication M × V?
23
a) [ ]
29
20
b) [ ]
24
28
c) [ ]
29
27
d) [ ]
18
89. A baker needs to schedule the production of two types of cakes: chocolate and vanilla. He
has limited resources for mixing ingredients and baking time. Each chocolate cake
requires 1 hour of mixing and 2 hours of baking, while each vanilla cake requires 1.5 hours
of mixing and 1 hour of baking. If he has a total of 5 hours for mixing and 6 hours for
baking, what is the maximum number of chocolate cakes he can bake if he chooses to
bake only chocolate cakes?
a) 3
b) 2
c) 4
d) 5
90. The baker decides to bake a mix of chocolate and vanilla cakes to maximize his profit.
Chocolate cakes provide a profit of $5 each, while vanilla cakes provide a profit of $3
each. If he can only bake a maximum of 3 cakes in total (of either type) due to oven
constraints, and he has the resources to bake any mix of the two types, what is the
combination that maximizes his profit?
a) 3 chocolate cakes
b) 2 chocolate cakes and 1 vanilla cake
c) 1 chocolate cake and 2 vanilla cakes
d) 3 vanilla cakes
91. A company has employee data stored in a dictionary called employees , where each key is
an employee's ID and the value is another dictionary with the employee's details, such as
name, department, and salary.
Example:
employees = {
101: {"name": "Alice", "department": "Sales", "salary": 50000},
102: {"name": "Bob", "department": "Engineering", "salary": 60000},
103: {"name": "Charlie", "department": "Marketing", "salary": 55000},
}
The company wants to give a 10% raise to all employees in the Engineering department. After
implementing the raise, what will be the new salary of employee 102 (Bob)?
a) 60000
b) 66000
c) 61000
d) 70000
92. Given a dictionary inventory that keeps track of products in a store, where keys are
product names and values are the number of items in stock. The store owner wants to
check if any product's stock has dropped below a threshold of 5 and, if so, update a list
low_stock_items with the names of these products.
Example:
inventory = {
"apples": 10,
"bananas": 3,
"oranges": 7,
"pears": 2
}
a) ["apples", "oranges"]
b) ["bananas", "pears"]
c) ["apples", "bananas", "pears"]
d) ["bananas"]
93. What will be the output when evaluating the following code?
result = 5 + 3 * 2 ** 2 + 10 // 5
print(result)
for i in range(3):
for j in range(2):
if i == j:
continue
if i == 1:
break
print(i, j)
How many times will the print(i, j) statement execute?
a = (1, 2, 3)
b = (a, 4)
b[0] = 10
print(b)
a) (10, 2, 3), 4
b) (1, 2, 3), 4
c) Error
d) (10, 4)
Python Code:
Hello World!
a) Hello
b) Hello World!
c) Error
d) World!
97. Which of the following statements are true regarding Python’s exception handling?
a) The finally block is executed only if an exception is raised.
b) The finally block is executed only if an exception is not raised.
c) try block can have multiple except blocks.
d) You can define custom exceptions by inheriting from Exception .
98. Given an unsorted list of 8 elements, how many comparisons will the Bubble Sort
algorithm require in the worst case?
99. In a Caesar cipher with a shift of 3 , what will the encrypted form of the word "HELLO" be?
a) KHOOR
b) EKRRJ
c) HELLO3
d) IGOPT
def func(nums):
for i in range(len(nums)):
if nums[i] % 2 == 0:
nums[i] += 1
return sum(nums)
nums = [1, 2, 3, 4]
print(func(nums))
a) 11
b) 12
c) 13
d) 14
f = outer(5)
print(f())
a) 5
b) 6
c) 7
d) Error
102. What is the result of the following code snippet using list comprehension?
lst = [1, 2, 3, 4, 5]
result = [x**2 for x in lst if x > 2]
print(result)
nums = [1, 2, 3]
matrix = [[n * m for m in nums] for n in nums]
print(matrix)
105. What will be the final value of count after executing this code?
count = 0
for i in range(1, 10):
if i % 3 == 0:
count += i
print(count)
a) 12
b) 18
c) 24
d) 9
106. What is the output of the following code when slicing a string?
s = "Python Programming"
print(s[::-1][7:])
a) gnimmargorp
b) gnimmargorp nohtyp
c) gnimmargorp gnohtyp
d) gorP nohtyP
107. What does the following code output if nums = [1, 2, 3, 4, 5] ?
a) [4]
b) [2, 4]
c) [4, 5]
d) [3, 5]
def mystery(val):
return val % 3 == 0 and val % 5 == 0
a) 1
b) 2
c) 3
d) 4
109. What will be printed by this code involving string slicing and list comprehension?
text = "ABCDEFG"
result = [text[i] for i in range(len(text)) if i % 2 == 0]
print("".join(result))
a) ACEG
b) BDF
c) ACE
d) BDFH