11 questions · 37.5 marks · 8 papers. Try each one before checking.
Solve them and check answers →Read the notes first
24 Mar 2024
Question 10 MCQ · 3 marks
Consider the following Python code snippet.
def modify(func):
def wrapper(name):
print("Before function execution")
result = func(name)
print("After function execution")
return result
return wrapper
@modify
def greet(name):
return f"Hello, {name}!"
print(greet("Ram"))
What will be the output of the code on the terminal?
Before function execution
After function execution
Hello, Ram!
Hello, Ram!
Before function execution
After function execution
Before function execution
Hello, Ram!
After function execution
Hello, Ram!
Question 11 MCQ · 4.5 marks
Consider the following Python code snippet.
import logging
import sys
logging.basicConfig(level=logging.INFO,
format='%(levelname)s - %(message)s')
num1, num2 = int(sys.argv[1]), int(sys.argv[2])
logging.info("This operation checks factors")
if num1 % num2 == 0:
logging.debug(f"{num2} is a factor of {num1}")
else:
logging.warning(f"{num2} is not the factor of {num1}")
What will be the output of the above code on the terminal for the command:
python log.py 25 5
INFO - This operation checks factors
WARNING - 5 is not the factor of 25
INFO - This operation checks factors
DEBUG - 5 is a factor of 25
INFO - This operation checks factors
DEBUG - 5 is a factor of 25
04 Aug 2024
Question 6 MCQ · 3 marks
Consider the following Python code snippet, and select the correct output list if the code is run on the terminal.
def modify(func):
def wrapper(l):
res = func(l)
return res[::-1]
return wrapper
def update (func):
def wrapper(l):
res = func(l)
return list(map(lambda x: x/2, res))
return wrapper
@modify
@update
def mylist(l):
out_list = []
for i in l:
out_list.append(i**2)
return out_list
print(mylist([2,4,1,7,5,9]))
[0.25, 1, 4, 6.26, 12.25, 20.25][1, 4, 0.25, 12.25, 6.25, 20.25][40.5, 12.5, 24.5, 0.5, 8.0, 2.0][0.5, 2.0, 8.0, 12.5, 24.5, 40.5]
Question 17 MCQ · 4.5 marks
Consider the following Python code snippet.
Filename: code.py
import logging
import sys
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
logging.warning('This is only for testing.')
if sys.argv[1] == 'info':
logging.info('This code is working as expected.')
if sys.argv[1] == 'debug':
logging.debug('This code may have issues, debugging...')
logging.warning('code execution complete!')
What will be output on the terminal is the above code snippet is run on the terminal using command: python code.py debug
WARNING:This is only for testing.
INFO: This code is working as expected
WARNING:code execution complete!
WARNING:This is only for testing.
DEBUG: This code may have issues, debugging...
WARNING:code execution complete!
WARNING:This is only for testing.
WARNING:code execution complete!
INFO: This code is working as expected
DEBUG: This code may have issues, debugging...
16 Mar 2025
Question 5 MCQ · 3 marks
Consider the following Python code snippet.
def update(func):
def wrapper(N):
out = []
for i in range(N):
if i % 2 == 0:
out.append(i**3)
else:
out.append(i**2)
return out
return wrapper
@update
def func(N):
if N % 2 == 0:
return N**2
else:
return N**3
print(func(5))
What will be the output of the above code in the terminal?
25125[0, 1, 4, 27, 16][0, 1, 8, 9, 64]
03 Aug 2025
Question 7 MCQ · 3 marks
Consider the following Python code.
File name: main.py
def calculate(funx):
def wrapper(a, b):
x = funx(a, b)
return x**2
return wrapper
@calculate
def foo(x, y):
return x - y
# main code
print(foo(5, 2))
What is the correct output of the given code?
- 10
- 9
- 3
- 4
14 Aug 2026
Question 4 MCQ · 3 marks
Consider the following Python code. File name: decorator.py
def loggerDecorator(func):
def inner_wrapper():
print("Function execution started")
res1 = func()
res2 = func()
return res1, res2
return inner_wrapper
@loggerDecorator
def getData():
return "Data retrieved"
print(getData())
What will be the output, when running the above code using the command "python decorator.py"?
('Data retrieved', 'Data retrieved')
Function execution started
Function execution started
Data retrieved
Data retrieved
Function execution started
('Data retrieved', 'Data retrieved')
Data retrieved
Data retrieved
Function execution started
Aug 2023
Question 6 MCQ · 3 marks
What will be the output of the following Python code snippet on the terminal?
def modify(n):
def modifier(n):
ser = [0, 1]
for i in range(n-2):
new = ser[i] + ser[i+1]
ser.append(new)
print(ser)
return modifier
@modify
def list_num(n):
nums = []
for i in range(n):
nums.append(i+1)
print(nums)
list_num(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][1, 2, 3, 4, 5, 6, 7, 8, 9, 10][0, 1, 1, 2, 3, 5, 8, 13, 21][0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Dec 2023
Question 17 MCQ · 3 marks
What will be the output of the following Python code snippet?
def modify(func):
def wrapper (n):
mylist = []
for i in range(1, n + 1):
if n % i == 0:
mylist.append(i)
return mylist
return wrapper
@modify
def myFunc(n):
mylist = []
for i in range(1, n + 1):
if i % 2 == 0:
mylist.append(i)
return mylist
print(myFunc(14))
[1, 3, 5, 7, 9, 11, 13][2, 4, 6, 8, 10, 12, 14][1, 2, 7, 14][1, 3, 5, 7, 11, 13]
Question 19 MSQ · 4.5 marks
Consider the following Python code snippet.
Filename: log.py
import logging
import sys
logging.basicConfig(level=logging.WARNING,
format='%(levelname)s - %(message)s')
num1, num2 = int(sys.argv[1]), int(sys.argv[2])
if num2 > 0:
logging.debug(f"Division {num1}/{num2} is possible")
else:
logging.critical("FATAL - Division by zero is not possible")
Which of the following statements is/are correct?
- For the command:
python log.py 12 24
The output on the terminal will be:
DEBUG - Division 12/24 is possible - For the command:
python log.py 0 24
The output on the terminal will be:
DEBUG - Division 0/24 is possible - For the command:
python log.py 15 0
The output on the terminal will be:
CRITICAL - FATAL - Division by zero is not possible - For the command:
python log.py 0 0
The output on the terminal will be:
CRITICAL - FATAL - Division by zero is not possible
06 Apr 2026
Question 4 MCQ · 3 marks
Consider the following Python code.
def modify(func):
def wrapper(p, q):
result = func(p, q)
return result + 5
return wrapper
@modify
def bar(a, b):
return a * b
print(bar(2, 3))
Which of the following is the correct output of the above code?
- 56
- 11
- 6
- 30
Check your answers →
Weeks covering this topic
Other MAD 1 topics