O Level Python Paper January 2023
निम्नलिखित कोड का परिणाम क्या है स्निपेट?
What is the output of the following code snippet ?
print([i.lower() for i in “HELLO”]) Sure!
The code converts each character in "HELLO" to lowercase using .lower(), resulting in the list ['h', 'e', 'l', 'l', 'o'].
Answer: (B) ['h', 'e', 'l', 'l', 'o'].
Correct Answer: B) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
निम्नलिखित का आउटपुट क्या होगा छद्म कोड?
What will be the output of the following pseudo code ?
Integer a, b
Set a = 10, b = 5
a = a mod (a - 6)
b = b mod (b - 2)
Print a – b
Sure!
a = 10 mod (10 - 6) = 10 mod 4 = 2b = 5 mod (5 - 2) = 5 mod 3 = 2- Then,
a - b = 2 - 2 = 0.
Answer: (B) 0.
Correct Answer: B) 0
निम्नलिखित का आउटपुट क्या होगा छद्म कोड, जहां संचालन और प्रतिनिधित्व करते हैं?
What will be the output of the following pseudo code, where & represent And operation ?
Integer a, b, c
Set b = 5, a = 1
c = a & b
Print c Sure!
a = 1(binary0001),b = 5(binary0101).- The AND operation (
&) compares each bit:0001 & 0101 = 0001(which is1).
So, the output is 1.
Answer: (A) 1.
Correct Answer: A) 1
निम्नलिखित कोड का परिणाम क्या है ? एनपी के रूप में सुन्न आयात करें
What is the output of the following code ?
import numpy as np
a = np.array([1,2,3,5,8])
b = np.array([0,3,4,2,1])
c = a + b
c = c*a
print (c[2]) Sure!
c = a + b→[1, 5, 7, 7, 9]c = c * a→[1, 10, 21, 35, 72]c[2]is21.
Answer: (B) 21.
Correct Answer: C) 12
निम्नलिखित कोड का आउटपुट क्या है? एनपी के रूप में सुन्न आयात करें
What is the output of following code ? import numpy as np
a = np.array([[1,2,3],[4,5,6]])
print(a.shape)
Let's break down the code:
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a.shape)
ais a 2x3 numpy array (2 rows and 3 columns).- The
.shapeattribute of a numpy array returns a tuple representing the dimensions of the array.
So, for this array:
- It has 2 rows and 3 columns, so the shape will be
(2, 3).
Answer: (A) (2, 3).
Correct Answer: A) (2, 3)
निम्नलिखित कथन में 'f' क्या है?
What is ‘f’ in the following statement ?
f=open(“Data.txt”, “r”) In the statement:
f = open("Data.txt", "r")
fis a file handle. It's a reference to the file that has been opened, allowing you to perform operations (like reading, writing) on the file.
So, the correct answer is:
Answer: (B) File Handle.
Correct Answer: B) File Handle
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
WM=[‘b’ * x for x in range(4)]
print(WM) Let's break down the code:
WM = ['b' * x for x in range(4)]
print(WM)
-
The list comprehension
['b' * x for x in range(4)]iterates over the range of numbers from0to3. -
In each iteration, it multiplies the string
'b'by the current value ofx. -
For
x = 0:'b' * 0results in an empty string''. -
For
x = 1:'b' * 1results in'b'. -
For
x = 2:'b' * 2results in'bb'. -
For
x = 3:'b' * 3results in'bbb'.
So, the list WM will be: ['', 'b', 'bb', 'bbb'].
Answer: (A) ['', 'b', 'bb', 'bbb'].
Correct Answer: A) [‘’, ‘b’, ‘bb’, ‘bbb’]
निम्नलिखित कोड का परिणाम क्या है ? एनपी के रूप में सुन्न आयात करें
What is the output of the following code ? import numpy as np
a = np.array([1,2,3])
print(a.ndim) Let's break down the code:
import numpy as np
a = np.array([1, 2, 3])
print(a.ndim)
ais a 1-dimensional numpy array (since it is a single list with elements[1, 2, 3]).- The
.ndimattribute of a numpy array gives the number of dimensions of the array.
For a = np.array([1, 2, 3]), it is a 1D array, so a.ndim will return 1.
Answer: (A) 1.
Correct Answer: A) 1
निम्नलिखित कोड के लिए आउटपुट क्या होगा?
What will be output for the following code ?
import numpy as np
a = np.array([[1,2,3],[0,1,4]])
print (a.size) Sure!
The array a has 2 rows and 3 columns, so the total number of elements is 2 * 3 = 6.
Answer: (C) 6.
Correct Answer: C) 6
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of following ?
Y=[2,5J,6]
Y.sort() Let's break down the code:
Y = [2, 5j, 6]
Y.sort()
Yis a list containing elements:2,5j(a complex number), and6.- The
sort()method in Python does not work with mixed data types such as integers and complex numbers because they cannot be directly compared.
Since you cannot compare integers with complex numbers in Python, this will result in an error.
Answer: (C) Error.
Correct Answer: C) Error
x का डेटाटाइप क्या है?
What is the datatype of x ?
import numpy as np
a=np.array([1,2,3,4])
x= a.tolist() Let's break down the code:
import numpy as np
a = np.array([1, 2, 3, 4])
x = a.tolist()
ais a numpy array.- The method
.tolist()converts a numpy array into a Python list.
So, the variable x will be a list.
Answer: (D) list.
Correct Answer: D) list
निम्नलिखित का आउटपुट क्या होगा पायथन कोड?
What will be the output of the following Python code ?
>>>list1 = [1, 3]
>>>list2 = list1
>>>list1[0] = 4
>>>print(list2) Sure!
list2is just a reference tolist1.- When
list1[0]is changed to4, it also affectslist2because both point to the same list.
Answer: (C) [4, 3].
Correct Answer: C) [4, 3]
निम्नलिखित कथन का परिणाम क्या होगा?
What will be the output of following statement ?
>>>”m”+”nl” Let's break down the statement:
"m" + "nl"
- This is string concatenation, where the string
"m"is combined with the string"nl". - The result will be the two strings joined together:
"mnl".
Answer: (B) 'mnl'.
Correct Answer: B) ‘mnl’
निम्नलिखित स्निपेट कोड का आउटपुट क्या होगा?
What will be the output of the following code snippet ?
d = {3, 4, 5}
for k in d:
print(k) निम्नलिखित कोड खंड क्या प्रिंट करेगा?
What will following code segment print ?
if True or True:
if False and True or False:
print(‘A’)
elif False and False or True and True:
print(‘B’)
else:
print(‘C’)
else:
print(‘D’) Sure!
True or TrueisTrue, so the first block is executed.- The second condition
False and True or FalseisFalse, so it moves toelif. False and False or True and TrueisTrue, so it prints'B'.
Answer: (B) B.
Correct Answer: B) B
निम्नलिखित का आउटपुट क्या होगा पायथन कोड?
What will be the output of the following Python code ?
example = “helle”
example.rfind(“e”) Let's break down the code:
example = "helle"
example.rfind("e")
rfind()returns the highest index of the substring (in this case,"e") found in the string.- In the string
"helle", the last occurrence of"e"is at index4.
So, the output will be 4.
Answer: (C) 4.
Correct Answer: C) 4
निम्नलिखित पायथन कोड का आउटपुट क्या है?
What is the output of following Python code ?
>>>print(5*(2//3)) निम्नलिखित कोड के लिए आउटपुट क्या होगा?
What will be output for the following code ?
import numpy as np
a = np.array([1,2,3,5,8])
print (a.ndim) Let's break down the code:
import numpy as np
a = np.array([1, 2, 3, 5, 8])
print(a.ndim)
ais a 1-dimensional numpy array because it's a single list[1, 2, 3, 5, 8].- The
.ndimattribute of a numpy array tells us the number of dimensions of the array.
For the array a = np.array([1, 2, 3, 5, 8]), it is 1D.
So, the output will be 1.
Answer: (B) 1.
Correct Answer: B) 1
निम्नलिखित का आउटपुट क्या होगा पायथन कोड?
What will be the output of the following Python code ?
from math import *
floor(11.7) Let's break down the code:
from math import *
floor(11.7)
- The
floor()function returns the largest integer less than or equal to the given number. - For
11.7, the largest integer less than or equal to it is11.
So, the output will be 11.
Answer: (B) 11.
Correct Answer: B) 11
का आउटपुट क्या होगा a=5, b=8, c=6 के लिए निम्नलिखित एल्गोरिदम का आउटपुट क्या होगा ?
What will be the output of the following algorithm for a=5, b=8, c=6 ?
Step 1 : Start
Step 2 : Declare variables a, b and c.
Step 3 : Read variables a, b and c.
Step 4 : If a < b
If a < c
Display a is the smallest number.
Else
Display c is the smallest number.
Else
If b < c
Display b is the smallest number.
Else
Display c is the smallest number.
Step 5 : Stop
Here's a concise breakdown:
- a = 5, b = 8, c = 6.
- First, we check if
a < b, which is true (5 < 8). - Then, we check if
a < c, which is also true (5 < 6). - Since both conditions are true, the output will be "a is the smallest number".
Answer: (A) a is the smallest number.
Correct Answer: A) a is the smallest number
निम्नलिखित में से कौन सी त्रुटि दिया गया कोड लौटाई गई है?
Which of the following error is returned by the given code ?
>>> f = open(“test.txt”,”w”)
>>> f.write(345) Let's analyze the given code:
f = open("test.txt", "w")
f.write(345)
- The
open()function is used to open a file in write mode ("w"). - The
write()method expects a string as an argument, but345is an integer. - Trying to write an integer directly will cause an error because the
write()method cannot handle non-string data types.
The error will be:
TypeError because you're passing an integer instead of a string to the write() method.
Answer: (B) Type Error.
Correct Answer: B) Type Error
निम्नलिखित का आउटपुट क्या होगा पायथन कोड?
What will be the output of the following Python code ?
from math import factorial
print(math.factorial(5)) Sure!
- You imported
factorialdirectly, so you should usefactorial(5), notmath.factorial(5). - Using
math.factorial(5)will give an error becausemathwasn't imported.
Answer: (D) Error, the statement should be: print(factorial(5)).
Correct Answer: D) Error, the statement should be : print(factorial(5))
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
y = ‘klmn’
for i in range(len(y)):
print(y) Let's break down the code:
y = 'klmn'
for i in range(len(y)):
print(y)
y = 'klmn'is a string.len(y)is4because the string "klmn" has 4 characters.- The loop runs 4 times (because
range(4)generates the values0, 1, 2, 3). - In each iteration, it prints the entire string
y, which is"klmn".
So the output will be:
klmn
klmn
klmn
klmn
Answer: (A) klmn klmn klmn klmn.
Correct Answer: A) klmn klmn klmn klmn
निम्नलिखित पायथन कोड का आउटपुट क्या होगा ?
What will be the output of the following Python code ?
x = ‘abcd’
for i in x:
print(i.upper()) The code iterates through each character in the string 'abcd', and for each character, it prints the uppercase version using .upper(). So it will print:
A
B
C
D
Answer: (D) A B C D.
Correct Answer: D) A B C D
निम्नलिखित कोड स्निपेट का आउटपुट क्या होगा?
What will be the output of the following code snippet ?
from math import *
a = 2.19
b = 3.999999
c = -3.30
print(int(a), floor(b), ceil(c), fabs(c)) Here’s a quick breakdown:
int(a): Converts2.19to2.floor(b): Floors3.999999to3.ceil(c): Ceils-3.30to-3.fabs(c): Converts-3.30to its absolute value3.30.
So, the output will be:
2 3 -3 3.3
Answer: (C) 2 3 -3 3.
Correct Answer: C) 2 3 -3 3
निम्नलिखित कोड के लिए आउटपुट क्या होगा?
What will be output for the following code ?
import numpy as np
ary = np.array([1,2,3,5,8])
ary = ary + 1
print (ary[1]) Let's analyze the code:
import numpy as np
ary = np.array([1, 2, 3, 5, 8])
ary = ary + 1
print(ary[1])
Step-by-step breakdown:
ary = np.array([1, 2, 3, 5, 8]): Creates a NumPy array with elements[1, 2, 3, 5, 8].ary = ary + 1: Adds1to each element of the array. This will give[2, 3, 4, 6, 9].print(ary[1]): Prints the element at index1of the modified array, which is3.
So, the output will be:
3
Answer: (D) 3.
Correct Answer: D) 3
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
a = set(‘abc’)
b = set(‘cdef’)
print(a&b) Here’s a quick explanation:
a = set('abc')creates a set{'a', 'b', 'c'}.b = set('cdef')creates a set{'c', 'd', 'e', 'f'}.a & bgives the intersection (common elements) of both sets. The common element is'c'.
So, the output is:
{'c'}
Answer: (A) {'c'}.
Correct Answer: A) {‘c’}
निम्नलिखित में से कौन शब्दकोश में key=”tiger” के लिए कुंजी-मान को हटा देगा?
Which of the following will delete key-value pair for key=”tiger” in dictionary ?
dic={“lion”:”wild”,”tiger”:”wild”,”cat”:”domestic”,“dog”.”domestic”} To delete the key-value pair for "tiger" in the dictionary, you use the del statement:
del dic["tiger"]
This removes the key "tiger" and its value from the dictionary.
Correct answer: (A) del dic["tiger"].
Correct Answer: A) del dic[“tiger”]
निम्नलिखित Python का कोड क्या है?
What is the value of the following Python code ?
>>>print(36 / 4) The Python code print(36 / 4) will perform division, and in Python 3, division always returns a floating-point number, even if the result is a whole number.
So, the result of 36 / 4 will be 9.0, which is a float.
Thus, the correct answer is:
(C) 9.0
Correct Answer: C) 9.0
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following ?
print(sum(1,2,3)) The sum() function in Python takes an iterable (like a list or tuple) as its argument. However, in the code sum(1, 2, 3), three separate arguments are passed to the function, which is incorrect. The function expects a single iterable (like a list or tuple), not multiple individual numbers.
So, the code will raise a TypeError.
Thus, the correct answer is:
(A) Error
Correct Answer: A) Error
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
n=5
while n>0:
n-=1
if n ==2:
continue
print(n) Sure! Here's a simpler explanation:
- Initially,
n = 5. - The loop runs while
n > 0, and in each iteration,nis reduced by 1. - When
n == 2, thecontinueskips printingnand moves to the next iteration.
Step-by-step output:
n = 5→ print 4n = 4→ print 3n = 3→ skip printing (becausen = 2)n = 1→ print 1n = 0→ loop ends
So the output is: 4 3 1 0
Answer: (B) 4 3 1 0
Correct Answer: B) 4 3 1 0
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
print(max([1, 2, 3, 4], [4, 5, 6], [7])) The max() function compares the first element of each list:
- First list:
[1, 2, 3, 4](first element: 1) - Second list:
[4, 5, 6](first element: 4) - Third list:
[7](first element: 7)
Since 7 is the largest, the function returns the list [7].
Answer: (B) [7]
Correct Answer: B) [7]
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
m = 0
while m < 5:
print(m)
m += 1
if m == 3:
break
else:
print(0) Here’s how the code works:
- First iteration: Prints
0, then0again (sincem != 3). - Second iteration: Prints
1, then0again. - Third iteration: Prints
2, then the loop stops becausem == 3.
Output: 0 0 1 0 2
Answer: (C) 0 0 1 0 2
Correct Answer: B) 0 1 2
निम्नलिखित अभिव्यक्ति का आउटपुट क्या होगा?
What will be the output of the following expression ?
x = 14
print(x>>2) The operation x >> 2 shifts the bits of x (14) two places to the right.
14in binary is1110.- After shifting right by 2, it becomes
0011, which is3in decimal.
So, the output is 3.
Answer: (C) 3
Correct Answer: C) 3
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
n2=4
def s(n1):
print(n1)
n1 = n1 +2
n2=4
s(n2)
print(n2) Here's how the code works:
n2is4globally.- Inside the function
s(n1),n1is set to4(fromn2). - The function prints
4(the value ofn1). - Modifying
n1inside the function doesn't affect the globaln2. - After the function, the global
n2remains4.
Output: 4 4
Answer: (C) 4 4
Correct Answer: C) 4 4
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
def func(a, b=5, c=10):
print(‘a is’, a, ‘and b is’, b, ‘and c is’, c)
func(13, 17)
func(a=2, c=4)
func(5,7,9) Here's the breakdown:
-
First call:
func(13, 17)a = 13,b = 17,c = 10(default).
Output:a is 13 and b is 17 and c is 10.
-
Second call:
func(a=2, c=4)a = 2,b = 5(default),c = 4.
Output:a is 2 and b is 5 and c is 4.
-
Third call:
func(5, 7, 9)a = 5,b = 7,c = 9.
Output:a is 5 and b is 7 and c is 9.
Final output:
a is 13 and b is 17 and c is 10
a is 2 and b is 5 and c is 4
a is 5 and b is 7 and c is 9
Answer: (C)
Correct Answer: C) a is 13 and b is 17 and c is 10 a is 2 and b is 5 and c is 4 a is 5 and b is 7 and c is 9
निम्नलिखित कोड स्निपेट का आउटपुट क्या होगा?
What will be the output of the following code snippet ?
numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
odd_numbers = [x for x in sorted_numbers if
x % 2 != 0]
print(odd_numbers) Here’s how the code works:
- The tuple
numbersis sorted:[2, 4, 7, 19, 22, 45, 72, 89]. - It then filters out the odd numbers:
[7, 19, 45, 89]. - Finally, it prints the list of odd numbers.
Output: [7, 19, 45, 89]
Answer: (A)
Correct Answer: A) [7, 19, 45, 89]
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
d1={“abc”:5,”def”:6,”ghi”:7}
print(d1[0]) निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
len([“hello”,2, 4, 6]) निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
def display(b, n):
while n>0:
print(b, end=””)
n=n-1
display(‘z’, 3) Let's break down the code:
def display(b, n):
while n > 0:
print(b, end="")
n = n - 1
display('z', 3)
- Function call:
display('z', 3)b = 'z'andn = 3.
- While loop: The loop runs while
n > 0. In each iteration:-
It prints
b(which is'z'). -
Decreases
nby 1. -
First iteration:
n = 3, print'z',nbecomes 2. -
Second iteration:
n = 2, print'z',nbecomes 1. -
Third iteration:
n = 1, print'z',nbecomes 0. The loop stops.
-
So, the output will be 'zzz'.
Answer: (A) zzz
Correct Answer: A) zzz
निम्नलिखित कोड के लिए आउटपुट क्या होगा?
What will be output for the following code ?
import numpy as np
a = np.array( [2, 3, 4, 5] )
print(a.dtype) एक स्ट्रिंग x=”hello” दिया गया x.count('l') का आउटपुट क्या है?
Given a string x=”hello” What is the output of x.count(‘l’) ?
The count() method in Python counts how many times a specified substring appears in a string.
For the string x = "hello", if you call x.count('l'), it counts the occurrences of the character 'l'.
- In the string
"hello", the letter'l'appears 2 times.
Thus, the output is:
(A) 2
Correct Answer: A) 2
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
x=123
for i in x:
print(i) The code:
x = 123
for i in x:
print(i)
The issue here is that x = 123 is an integer, and integers are not iterable in Python. You cannot loop through an integer directly like you can with a string, list, or other iterable objects.
So, this will result in an Error.
The correct answer is:
(C) Error
Correct Answer: C) Error
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
tuple1=(5,1,7,6,2)
tuple1.pop(2)
print(tuple1) The issue here is that the pop() method is not available for tuples in Python. Tuples are immutable, meaning you cannot modify them by removing elements like you can with lists.
Since the pop() method is used for lists (not tuples), this will result in an Error.
The correct answer is:
(D) Error
Correct Answer: D) Error
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
def power(x, y=2):
r=1
for i in range(y):
r=r*x
return r
print (power(3))
print (power(3,3)) The power function calculates x raised to the power of y. By default, y = 2.
- First call:
power(3)→3^2 = 9 - Second call:
power(3, 3)→3^3 = 27
Output:
9 27
Answer: (B) 9 27
Correct Answer: B) 9 27