O Level Python Paper July 2022 | Set 2
निम्नलिखित कोड के लिए आउटपुट क्या होगा?
What will be output for the following code ?
import numpy as np
a = np.array([[1,2,3],[0,1,4],[11,22,33]])
print (a.size) In the given code:
import numpy as np
a = np.array([[1, 2, 3], [0, 1, 4], [11, 22, 33]])
print(a.size)
Explanation:
ais a 2D NumPy array with the shape(3, 3)— it has 3 rows and 3 columns.- The
.sizeattribute of a NumPy array gives the total number of elements in the array.
Since the array a has 3 rows and 3 columns, the total number of elements is:
3 * 3 = 9
Answer: (C) 9
Correct Answer: C) 9
निम्नलिखित कथनों के बाद आउटपुट क्या होगा?
What will be the output after the following statements?
a = 0
b = 3
while a + b < 8:
a += 1
print(a, end='') निम्नलिखित कोड क्या प्रिंट करता है?
What does the following code print ?
if 2 + 5 == 8:
print("TRUE")
else:
print("FALSE")
print("TRUE")
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following?
print((range(4)))
In Python 3, range(4) produces a range object, which is a sequence of numbers from 0 to 3, but not a list. So, when you print range(4), it shows the object representation, like range(0, 4).
Answer: (C) range(0,4)
Correct Answer: C) range(0,4)
निम्नलिखित कोड का आउटपुट क्या होगा?
What will be the output of the following code ?
f=open("demo.txt","r")
print(f.tell()) निम्नलिखित कोड का आउटपुट क्या होगा?
What will be the output of the following code ?
f=open("demo.txt","w+")
f.write("Welcome to Python")
f.seek(5)
a=f.read(5)
print(a) The code works as follows:
- The file
"demo.txt"is opened in write and read mode (w+). - The string
"Welcome to Python"is written into the file. - After writing,
f.seek(5)moves the file pointer to position 5 (the sixth character, which is'o'in the word"Welcome"). f.read(5)reads the next 5 characters from the current position.
So, the output will be the next 5 characters starting from position 5, which is "me to".
Therefore, the correct answer is:
(B) me to
Correct Answer: B) me to
निम्नलिखित अभिव्यक्ति का आउटपुट क्या होगा?
What will be the output of the following expression ?
a = 2
b = 8
print(a | b)
print(a >> 1) निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following ?
import numpy as np
a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
print(a[2,2]) The code creates a 3x4 matrix a. When you access a[2,2], it refers to the element at row 2, column 2 (remember, Python uses 0-based indexing).
Here’s the matrix:
Row 0: [1, 2, 3, 4]
Row 1: [5, 6, 7, 8]
Row 2: [9, 10, 11, 12]
So, a[2,2] gives the value 11.
Answer: (B) 11
Correct Answer: B) 11
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
def add(a, b):
return a+5, b+5
result = add(3, 2)
print(result) Let's break down the code:
The function add(a, b) takes two arguments, a and b, and returns two values: a+5 and b+5.
In this case, the function is called with a = 3 and b = 2. So:
a + 5 = 3 + 5 = 8b + 5 = 2 + 5 = 7
The function returns the tuple (8, 7).
When you print the result, it will display the tuple (8, 7).
Answer: (C) (8, 7).
Correct Answer: C) (8,7)
मान लीजिए q= [3, 4, 5, 20, 5, 25, 1, 3], तो q.pop(1) के बाद q सूची के आइटम क्या होंगे?
Assume q= [3, 4, 5, 20, 5, 25, 1, 3], then what will be the items of q list after q.pop(1) ?
The pop() method removes an item from the list at the specified index and returns the removed item.
In this case, q.pop(1) removes the item at index 1 from the list q.
Here's the list before and after using pop(1):
- Initial list:
q = [3, 4, 5, 20, 5, 25, 1, 3] - After
q.pop(1), the item at index 1 (which is4) is removed, so the list becomes:q = [3, 5, 20, 5, 25, 1, 3]
Thus, the list after q.pop(1) is [3, 5, 20, 5, 25, 1, 3].
Answer: (C) [3, 5, 20, 5, 25, 1, 3].
Correct Answer: C) [3, 5, 20, 5, 25, 1, 3]
निम्नलिखित कोड का परिणाम क्या है?
What is the output of the following code?
import numpy as np
a = np.array([1,2,3,5,8])
b = np.array([0,1,5,4,2])
c = a + b
c = c*a
print (c[2]) Let's simplify the explanation:
-
Arrays:
a = [1, 2, 3, 5, 8] b = [0, 1, 5, 4, 2] -
Adding arrays
aandb:c = a + b # [1+0, 2+1, 3+5, 5+4, 8+2] = [1, 3, 8, 9, 10] -
Multiplying
cbya:c = c * a # [1*1, 3*2, 8*3, 9*5, 10*8] = [1, 6, 24, 45, 80] -
Print the third element (
c[2]):print(c[2]) # This is 24
Output: 24
Answer: (B) 24
Correct Answer: B) 24
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
import numpy as np
a = np.array([[1,2,3]])
print(a.shape) Let's break it down:
-
Array
a:a = np.array([[1, 2, 3]])This creates a 2D array with one row and three columns:
[[1, 2, 3]] -
Shape of
a:print(a.shape)The shape of
ais(1, 3)because it has 1 row and 3 columns.
Output: (1, 3)
Answer: (C) (1, 3)
Correct Answer: C) (1, 3)
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
ms = ('A', 'D', 'H', 'U', 'N', 'I', 'C')
print(ms[1:4]) Sure! Here's a quick breakdown:
-
Tuple
ms:ms = ('A', 'D', 'H', 'U', 'N', 'I', 'C')It contains 7 elements:
'A', 'D', 'H', 'U', 'N', 'I', 'C'. -
Slicing
ms[1:4]:- This gets elements from index 1 to 3 (the 4th element is excluded).
- Index 1 =
'D' - Index 2 =
'H' - Index 3 =
'U'
So, ms[1:4] gives ('D', 'H', 'U').
Answer: (A) ('D', 'H', 'U').
Correct Answer: A) ('D', 'H', 'U')
>>>‟2‟+‟3‟ का आउटपुट क्या है
What is the output of >>>‟2‟+‟3‟
The code:
'2' + '3'
concatenates the two strings '2' and '3'. Since both are strings, it doesn't perform arithmetic addition but rather combines them into one string.
Output: '23'
Answer: (C) '23'
Correct Answer: C) ‟23‟
निम्नलिखित पायथन प्रोग्राम का आउटपुट क्या होगा?
What will be the output of the following Python program ?
def addItem(listParam):
listParam += [1]
mylist = [1, 2, 3, 4]
addItem(mylist)
print(len(mylist))
The code adds 1 to the list mylist by using += inside the addItem function. After calling addItem(mylist), the list becomes [1, 2, 3, 4, 1]. The length of the updated list is 5.
Answer: (A) 5
Correct Answer: A) 5
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code?
from math import *
floor(3.7)
The floor() function in Python returns the largest integer less than or equal to the given number.
In this case, floor(3.7) will return 3 because 3 is the greatest integer less than or equal to 3.7.
Answer: (A) 3
Correct Answer: A) 3
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
print(int()) In Python, calling int() without any arguments returns the default value of 0.
So, print(int()) will output 0.
Answer: (C) 0
Correct Answer: C) 0
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
a = set('dcma')
b = set('mlpc')
print(a^b)
निम्नलिखित कथन का आउटपुट क्या है?
What is the output of the following statement ?
print ((2, 4) + (1, 5)) The statement is performing tuple concatenation:
(2, 4)is a tuple.(1, 5)is another tuple.- The
+operator is used to concatenate both tuples.
So, the result will be (2, 4, 1, 5).
Thus, the output is:
(C) (2, 4, 1, 5).
Correct Answer: C) (2, 4, 1, 5)
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following ?
import sys
sys.stdout.write('Welcome\n')
sys.stdout.write('All\n') The sys.stdout.write() method in Python writes a string to the standard output (usually the console) without automatically adding a newline. The \n character in the first statement is used to print a newline after "Welcome."
So, the output will be:
Welcome
All
Thus, the correct answer is:
(A) Welcome All
Correct Answer: A) Welcome All
निम्नलिखित कोड से कितने नंबर प्रिंट होंगे?
How many numbers will be printed by the following code ?
def fun(a,b):
for x in range(a,b+1):
if x%3==0:
print(x, end=" ")
fun(100,120) The code checks for numbers divisible by 3 between 100 and 120. The numbers divisible by 3 in this range are:
102, 105, 108, 111, 114, 117, 120.
There are 7 such numbers, so the output will print 7 numbers.
Answer: (A) 7
Correct Answer: A) 7
निम्नलिखित कोड क्या प्रिंट करता है?
What does the following code print?
x = 'mohan'
for i in range(len(x)):
x[i].upper()
print (x) The code doesn't change the string x because strings are immutable in Python. The .upper() method creates a new string but doesn't modify the original string. Therefore, x remains 'mohan'.
So, the output is: (A) mohan.
Correct Answer: A) mohan
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following?
import numpy as np
a = np.array([1,5,4,7,8])
a = a + 1
print(a[1]) Let's break down the code:
- The array
ais created with the values[1, 5, 4, 7, 8]. - The operation
a = a + 1increments each element of the array by 1. So, the updated array will be[2, 6, 5, 8, 9]. - When
print(a[1])is called, it prints the element at index 1 of the updated array, which is6.
Thus, the correct output is: (C) 6.
Correct Answer: C) 6
निम्नलिखित कोड का परिणाम क्या है?
What is the output of the following code?
dict={"Joey":1,"Rachel":2}
dict.update({"Phoebe":2})
print(dict) The code initializes a dictionary with two key-value pairs: {"Joey": 1, "Rachel": 2}. Then, dict.update({"Phoebe": 2}) adds a new key "Phoebe" with value 2 to the dictionary.
The final dictionary becomes:
{"Joey": 1, "Rachel": 2, "Phoebe": 2}
So, the output is: (A) {"Joey":1, "Rachel":2, "Phoebe":2}.
Correct Answer: A) {"Joey":1,"Rachel":2,"Phoebe":2}
नीचे दिए गए प्रोग्राम का आउटपुट क्या है?
What is the output of below program ?
def maximum(x, y):
if x > y:
return x
elif x == y:
return 'The numbers are equal'
else:
return y
print(maximum(2, 3)) The function maximum(x, y) compares two values x and y.
- If
x > y, it returnsx. - If
x == y, it returns the string'The numbers are equal'. - Otherwise, it returns
y.
In this case, we call maximum(2, 3):
2is less than3, so the function will return3.
Hence, the output will be (B) 3
Correct Answer: B) 3
निम्नलिखित कथनों के बाद आउटपुट क्या होगा?
What will be the output after the following statements?
for i in range(1,6):
print(i, end='')
if i == 3:
break The code prints numbers from 1 to 3. When i == 3, the break statement stops the loop. So, the output is:
1 2 3.
Correct Answer: B) 1 2 3
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following ?
import numpy as np
print(np.maximum([2, 3, 4], [1, 5, 2]))
Sure!
np.maximum([2, 3, 4], [1, 5, 2]) compares the two lists element by element and returns the larger value at each position.
max(2, 1) = 2max(3, 5) = 5max(4, 2) = 4
So, the output is [2 5 4].
Answer: (D) [2 5 4].
Correct Answer: D) [2 5 4]
निम्नलिखित अभिव्यक्ति किस मूल्य का मूल्यांकन करती है?
What value does the following expression evaluate to ?
print(5 + 8 * ((3* 5)-9) /10)
The expression is:
5 + 8 * ((3 * 5) - 9) / 10
Step-by-step:
3 * 5 = 1515 - 9 = 68 * 6 = 4848 / 10 = 4.85 + 4.8 = 9.8
So, the result is 9.8.
Answer: (B) 9.8
Correct Answer: B) 9.8
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following ?
import numpy as np
a = np.array( [2, 3, 4, 5] )
b = np.arange(4)
print(a+b) Sure!
a = [2, 3, 4, 5]b = [0, 1, 2, 3](fromnp.arange(4))
Adding a and b element-wise:
2 + 0 = 23 + 1 = 44 + 2 = 65 + 3 = 8
So, the result is [2 4 6 8].
Answer: (D) [2 4 6 8].
Correct Answer: D) [2 4 6 8]
नीचे दिए गए प्रोग्राम का आउटपुट क्या है?
What is the output of below program ?
def say(message, times = 1):
print(message * times)
say('Hello')
say('World', 5)
Sure!
say('Hello')prints'Hello'(defaulttimes = 1).say('World', 5)prints'World'five times:'WorldWorldWorldWorldWorld'.
Output: Hello WorldWorldWorldWorldWorld.
Answer: (A) Hello WorldWorldWorldWorldWorld.
Correct Answer: A) Hello WorldWorldWorldWorldWorld
आउटपुट क्या है?
What is the output ?
def calc(x):
r=2*x**2
return r
print(calc(5)) Sure!
The function calculates 2 * x**2.
For x = 5:
5**2 = 252 * 25 = 50
So, the output is 50.
Answer: (B) 50.
Correct Answer: B) 50
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
def printMax(a, b):
if a > b:
print(a, 'is maximum')
elif a == b:
print(a, 'is equal to', b)
else:
print(b, 'is maximum')
printMax(3, 4) Sure!
- The function checks if
a > bora == b. - Since
3is less than4, it goes to theelseblock and prints4 is maximum.
So, the output is 4 is maximum.
Answer: (C) 4 is maximum.
Correct Answer: C) 4 is maximum
निम्नलिखित अभिव्यक्ति किस मूल्य का मूल्यांकन करती है?
What value does the following expression evaluate to ?
x = 5
while x < 10:
print(x, end='') Sure!
Since x is always 5 and there's no change to x inside the loop, the condition x < 10 will always be true. This causes the loop to run infinitely.
So, the result is an infinite loop.
Answer: (C) Infinite loop.
Correct Answer: C) Infinite loop
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
x = 50
def func (x) :
x = 2
func (x)
print ('x is now', x) Sure!
Inside the function, x is set to 2, but this only affects the local x. The global x remains 50.
So, the output is x is now 50.
Answer: (A) x is now 50.
Correct Answer: A) x is now 50
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
def disp(*arg):
for i in arg:
print(i)
disp(name="Rajat", age="20") Sure!
The function disp(*arg) expects positional arguments, but you passed keyword arguments (name="Rajat", age="20"). This causes a TypeError.
Answer: (A) TypeError.
Correct Answer: A) TypeError
निम्नलिखित फ़ंक्शन का रिटर्न प्रकार क्या है?
What is the return type of following function ?
def func1():
return “mnp‟,22 Let's analyze the function:
def func1():
return "mnp", 22
- The function is returning two values:
"mnp"and22, separated by a comma. - In Python, when multiple values are returned separated by a comma, they are returned as a tuple.
So, the return type of the function is tuple.
Answer: (D) tuple.
Correct Answer: D) tuple
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
def fun(a, b=6):
a=a+b
print(a)
fun(5, 4) Sure!
The function adds a and b.
In fun(5, 4), a = 5 and b = 4, so 5 + 4 = 9.
The output is 9.
Answer: (B) 9.
Correct Answer: B) 9
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code?
from math import pow
print(math.pow(2,3)) Sure!
You imported pow directly, so you should use pow(2, 3) instead of math.pow(2, 3).
Using math.pow(2, 3) causes an error.
Answer: (D) Error, the statement should be: print(pow(2, 3)).
Correct Answer: D) Error, the statement should be: print(pow(2, 3))
निम्नलिखित अभिव्यक्ति का आउटपुट क्या होगा?
What will be the output of the following expression ?
x = 4
print(x<<2) Sure!
The << operator shifts the bits to the left.
For x = 4 (binary 100), x << 2 shifts the bits two places left, giving 10000, which is 16.
Answer: (B) 16.
Correct Answer: B) 16
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
import numpy as np
y = np.array([[11, 12, 13, 14], [32, 33, 34, 35]])
print(y.ndim) Let's analyze the code:
import numpy as np
y = np.array([[11, 12, 13, 14], [32, 33, 34, 35]])
print(y.ndim)
yis a 2D array with 2 rows and 4 columns.- The
ndimattribute in NumPy returns the number of dimensions of the array.
Since y is a 2D array, y.ndim will return 2.
Answer: (B) 2.
Correct Answer: B) 2
निम्नलिखित अभिव्यक्ति का आउटपुट क्या होगा?
What will be the output of the following expression ?
print (7//2)
print (-7//2) Sure!
7 // 2gives3because floor division rounds down.-7 // 2gives-4because floor division rounds down towards the more negative number.
Answer: (C) 3 -4.
Correct Answer: C) 3 -4
निम्नलिखित छद्म कोड का आउटपुट क्या होगा?
What will be the output of the following pseudo-code ?
Integer a
Set a = 4
Do
print a + 2
a = a- 1
while (a not equals 0)
end while Sure!
- The loop starts with
a = 4and printsa + 2. - In each iteration,
adecreases by 1 untilareaches 0. - The printed values are:
6 (4 + 2),5 (3 + 2),4 (2 + 2), and3 (1 + 2).
Answer: (B) 6 5 4 3.
Correct Answer: B) 6 5 4 3
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
a = {1: "A", 2: "B", 3: "C"}
b = {4: "D", 5: "E"}
a.update(b)
print(a) Sure!
The update() method adds all key-value pairs from dictionary b to dictionary a.
So, a becomes {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}.
Answer: (B) {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}.
Correct Answer: B) {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
निम्नलिखित छद्मकोड का आउटपुट क्या होगा, जहां ʌ XOR ऑपरेशन का प्रतिनिधित्व करता है?
What will be the output of the following pseudocode, where ʌ represent XOR operation ?
Integer a, b, c
Set b = 4, a = 3
c = a ^ b
Print c Sure!
a = 3(binary0011) andb = 4(binary0100).- XOR (
^) gives1when bits are different,0when the same.
So, 3 ^ 4 = 7 (binary 0111).
Answer: (D) 7.
Correct Answer: D) 7
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following ?
def iq(a,b):
if(a==0):
return b
else:
return iq(a-1,a+b)
print(iq(3,6)) Sure!
The function iq recursively calls itself, reducing a and adding a to b each time.
iq(3, 6)→iq(2, 9)iq(2, 9)→iq(1, 11)iq(1, 11)→iq(0, 12)
When a = 0, it returns b, which is 12.
Answer: (D) 12.
Correct Answer: D) 12
निम्नलिखित कोड खंड क्या प्रिंट करेगा?
What will following code segment print ?
a = True
b = False
c = False
if not a or b:
print(1)
elif not a or not b and c:
print (2)
elif not a or b or not b and a:
print (3)
else:
print (4) Sure!
- First condition
not a or b:False or False→ False - Second condition
not a or not b and c:False or (True and False)→ False - Third condition
not a or b or not b and a:False or False or True→ True
So, it prints 3.
Answer: (B) 3.
Correct Answer: B) 3
निम्नलिखित कथनों के बाद आउटपुट क्या होगा?
What will be the output after the following statements?
x = 2
if x < 5:
print(x)
else:
pass Sure!
Since x = 2 and x < 5 is True, it prints x, which is 2.
Answer: (C) 2.
Correct Answer: C) 2
निम्नलिखित स्यूडोकोड का आउटपुट क्या होगा?
What will be the output of the following pseudocode ?
Integer a, b
Set a = 9, b = 5
a = a mod (a - 3)
b = b mod (b – 3)
Print a + b Sure!
a = 9 mod (9 - 3) = 9 mod 6 = 3b = 5 mod (5 - 3) = 5 mod 2 = 1- So,
a + b = 3 + 1 = 4.
Answer: (A) 4.
Correct Answer: B) 5