O Level Python Paper July 2022 | Set 1
आउटपुट निर्धारित करें:
Determine the output :
for i in range(20,30,10) :
j=i/2
print(j) Let's break down the code:
for i in range(20, 30, 10):
j = i / 2
print(j)
Explanation:
-
range(20, 30, 10)generates numbers starting from 20, ending before 30, with a step of 10.- This will generate the numbers:
20and30, but since the range is exclusive of 30, the loop will only run fori = 20.
- This will generate the numbers:
-
Inside the loop:
- For
i = 20,j = i / 2, soj = 20 / 2 = 10.0.
- For
-
print(j)will print10.0.
Output:
(C) 10.0
Correct Answer: C) 10.0
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following ?
import numpy as np
print(np.minimum([2, 3, 4], [1, 5, 2])) Let's analyze the given code:
import numpy as np
print(np.minimum([2, 3, 4], [1, 5, 2]))
Explanation:
np.minimum(a, b)compares two arrays element-wise and returns a new array containing the smaller value for each corresponding pair of elements.- In this case, we have two lists:
[2, 3, 4][1, 5, 2]
Comparing elements:
min(2, 1)→1min(3, 5)→3min(4, 2)→2
So, the result is [1, 3, 2].
Output:
(D) [1 3 2]
Correct Answer: D) [1 3 2]
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
print(bool(0), bool(3.14159), bool(3), bool(1.0+1j))
Let's break down the code:
print(bool(0), bool(3.14159), bool(3), bool(1.0+1j))
Explanation:
bool(0): In Python,0is considered a falsy value, sobool(0)isFalse.bool(3.14159): Any non-zero number (including floats like3.14159) is considered truthy, sobool(3.14159)isTrue.bool(3): Similarly, any non-zero integer is considered truthy, sobool(3)isTrue.bool(1.0 + 1j): A non-zero complex number (like1.0 + 1j) is also considered truthy, sobool(1.0 + 1j)isTrue.
Output:
(D) False True True True
Correct Answer: D) False True True True
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
def C2F(c) :
return c*9/5+32
print (C2F(100))
print (C2F(0)) Let's analyze the given Python code:
def C2F(c):
return c * 9 / 5 + 32
print(C2F(100))
print(C2F(0))
Explanation:
-
The function C2F(c) converts Celsius to Fahrenheit using the formula:
F=(95×C)+32F = \left( \frac{9}{5} \times C \right) + 32 -
For C2F(100):
- Substituting
c = 100into the formula: F=(95×100)+32=180+32=212.0F = \left( \frac{9}{5} \times 100 \right) + 32 = 180 + 32 = 212.0 - So,
C2F(100)returns212.0.
- Substituting
-
For C2F(0):
- Substituting
c = 0into the formula: F=(95×0)+32=0+32=32.0F = \left( \frac{9}{5} \times 0 \right) + 32 = 0 + 32 = 32.0 - So,
C2F(0)returns32.0.
- Substituting
Output:
(A) 212.0 32.0
Correct Answer: A) 212.0 32.0
निम्नलिखित में से कौन सा कथन अंतिम रूप से निष्पादित होगा?
Which of the following statement will execute in last ?
def s(n1): #Statement 1
print(n1) #Statement 2
n2=4 #Statement 3
s(n2) #Statement 4 Let's analyze the given code step by step:
def s(n1): # Statement 1
print(n1) # Statement 2
n2 = 4 # Statement 3
s(n2) # Statement 4
Execution Order:
- Statement 1: The function
s(n1)is defined. This statement does not execute anything immediately; it only defines the function. - Statement 3:
n2 = 4assigns the value4ton2. This is a regular assignment statement. - Statement 4:
s(n2)calls the functions()withn2(which is4). This triggers the execution of the function, so the next statement to execute is inside the function. - Statement 2: Inside the function,
print(n1)is executed, printing the value ofn1, which is4.
Conclusion:
The last statement to be executed is Statement 2, because it's inside the function s() and runs when the function is called in Statement 4.
Answer:
(B) Statement 2
Correct Answer: B) Statement 2
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
x = 'abcd'
for i in range(len(x)) :
i.upper()
print (x) निम्नलिखित कोड के लिए आउटपुट क्या होगा?
What will be output for the following code ?
import numpy as np
a = np.array([1,2,1,5,8])
b = np.array([0,1,5,4,2])
c = a + b
c = c*a
print (c[2]) Let's break down the code step by step:
import numpy as np
a = np.array([1, 2, 1, 5, 8])
b = np.array([0, 1, 5, 4, 2])
c = a + b # Element-wise addition of a and b
c = c * a # Element-wise multiplication of c and a
print(c[2]) # Print the third element of array c
Step-by-Step Explanation:
-
aandbarrays:a = np.array([1, 2, 1, 5, 8])b = np.array([0, 1, 5, 4, 2])
-
c = a + b:- Element-wise addition of
aandb:
c = [1+0, 2+1, 1+5, 5+4, 8+2] c = [1, 3, 6, 9, 10] - Element-wise addition of
-
c = c * a:- Element-wise multiplication of
canda:
c = [1*1, 3*2, 6*1, 9*5, 10*8] c = [1, 6, 6, 45, 80] - Element-wise multiplication of
-
print(c[2]):- The third element (index 2) of the array
cis6.
- The third element (index 2) of the array
Output:
(A) 6
Correct Answer: A) 6
नीचे दिए गए प्रोग्राम का आउटपुट क्या है?
What is the output of the below program ?
def func(a, b=5, c=10) :
print('a is', a, 'and b is', b, 'and c is', c)
func(3, 7)
func(25, c = 24)
func(c = 50, a = 100) Here’s a simple breakdown of the code:
-
func(3, 7):a = 3,b = 7(overrides default5),c = 10(default).- Output:
a is 3 and b is 7 and c is 10
-
func(25, c = 24):a = 25,b = 5(default),c = 24(overrides default).- Output:
a is 25 and b is 5 and c is 24
-
func(c = 50, a = 100):a = 100,b = 5(default),c = 50(overrides default).- Output:
a is 100 and b is 5 and c is 50
Final Output:
(C) a is 3 and b is 7 and c is 10 a is 25 and b is 5 and c is 24 a is 100 and b is 5 and c is 50
Correct Answer: C) a is 3 and b is 7 and c is 10 a is 25 and b is 5 and c is 24 a is 100 and b is 5 and c is 50
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
x = 50
def func(x):
print('x is', x)
x = 2
print('Changed local x to', x)
func(x)
print('x is now', x) Let's break down the code step by step:
x = 50 # Global variable x
def func(x):
print('x is', x) # Prints the value of x passed to the function
x = 2 # Local variable x is changed inside the function
print('Changed local x to', x) # Prints the new value of the local x
func(x) # Calls the function with the global x (which is 50)
print('x is now', x) # Prints the global x
Explanation:
-
x = 50: This sets the global variablexto50. -
Function Call:
func(x):- The function is called with the global
x(which is50). - Inside the function:
- The first
print('x is', x)prints the value of the parameterx(which is50). - The local
xis changed to2(this does not affect the globalx). - The second
print('Changed local x to', x)prints the new value of the localx(which is2).
- The first
- The function is called with the global
-
print('x is now', x):- After the function call, it prints the global
x, which remains unchanged at50, because the local change toxinside the function does not affect the global variable.
- After the function call, it prints the global
Final Output:
x is 50
Changed local x to 2
x is now 50
Answer:
(A) x is 50 Changed local x to 2 x is now 50
Correct Answer: A) x is 50 Changed local x to 2 x is now 50
कथन 3 के लिए उत्तर चुनें.
Choose the answer for statement 3.
import ___________ # statement 1
rec = [ ]
while True:
rn = int(input("Enter"))
nm = input("Enter")
temp = [rn, nm]
rec.append(temp)
ch = input("Enter choice (Y/N)")
if ch.upper == "N":
break
f = open("stud.dat", "____________") #statement 2
__________ .dump(rec, f) #statement 3
_______.close( ) # statement 4 Let's break down the code and identify the correct answer for Statement 3:
Given code structure:
import ___________ # statement 1
rec = [ ]
while True:
rn = int(input("Enter"))
nm = input("Enter")
temp = [rn, nm]
rec.append(temp)
ch = input("Enter choice (Y/N)")
if ch.upper == "N":
break
f = open("stud.dat", "____________") # statement 2
__________ .dump(rec, f) # statement 3
_______.close( ) # statement 4
Explanation:
-
import ___________(Statement 1):- The module needed for pickling (saving data to a file) in Python is
pickle.
So, the correct module to import is
pickle. - The module needed for pickling (saving data to a file) in Python is
-
f = open("stud.dat", "____________")(Statement 2):- This line is opening a file
stud.datin write mode. Since we're usingpickleto save the data, the correct mode would be"wb"(write binary mode). - So, the correct fill for this statement would be
"wb".
- This line is opening a file
-
__________ .dump(rec, f)(Statement 3):- The correct method to save data to a file using
pickleispickle.dump(). - So,
pickle.dump(rec, f)would serialize and save thereclist to the filef.
- The correct method to save data to a file using
-
_______.close()(Statement 4):- This closes the file
f, sof.close()is used here.
- This closes the file
Conclusion:
For Statement 3, the correct answer is pickle.dump().
Answer:
(B) pickle
Correct Answer: B) pickle
निम्नलिखित छद्म कोड का आउटपुट क्या होगा?
What will be the output of the following pseudo-code ?
Integer a
Set a = 5
do
print a - 2
a = a- 1
while (a not equals 0)
end while Let's break it down quickly:
- Initial value:
a = 5. - In each loop iteration:
- Prints
a - 2. - Decreases
aby 1.
- Prints
- The loop stops when
abecomes 0.
Iterations:
- First: prints
5 - 2 = 3,abecomes 4. - Second: prints
4 - 2 = 2,abecomes 3. - Third: prints
3 - 2 = 1,abecomes 2. - Fourth: prints
2 - 2 = 0,abecomes 1. - Fifth: prints
1 - 2 = -1,abecomes 0.
The loop stops when a = 0.
Output:
3 2 1 0 -1
So the correct answer is:
(D) None of these
Correct Answer: B) 3 0
रिक्त स्थान को भरें।
Fill in the blank.
import pickle
f=open(“data.dat”,"rb")
d=_____________.load(f)
f.close() The correct function to read a serialized object from a file using the pickle module is pickle.load().
Explanation:
pickle.load(f): This is used to load the data that was serialized and stored in a file (in this case,data.dat).
Answer:
(C) pickle
Correct Answer: C) pickle
कौन सा कथन फ़ाइल पॉइंटर को वर्तमान स्थिति से 10 बाइट्स पीछे ले जाएगा?
Which statement will move file pointer 10 bytes backward from current position ?
To move the file pointer 10 bytes backward from its current position, we need to use the seek() method in the following way:
f.seek(offset, whence):offset: The number of bytes to move the file pointer.whence: The reference point for theoffset.0: Start of the file (absolute positioning).1: Current position (relative to the current position).2: End of the file (relative to the end of the file).
To move the pointer backwards by 10 bytes, we use:
offset = -10(to move backward)whence = 1(relative to the current position)
Correct statement:
(B) f.seek(-10,1)
This will move the file pointer 10 bytes backward from its current position.
Answer:
(B) f.seek(-10,1)
Correct Answer: B) f.seek(-10,1)
निम्नलिखित लाइन को कार्यात्मक बनाने के लिए कौन सा मॉड्यूल आयात किया जाना चाहिए?
Which module to be imported to make the following line functional ?
sys.stdout.write(“ABC”)
The correct module to import for using sys.stdout.write() is the sys module. This module provides access to some variables used or maintained by the interpreter, including stdout, which is used for writing output.
Correct answer:
(D) sys
Correct Answer: D) sys
निम्नलिखित कोड का आउटपुट क्या होगा?
What will be the output of following code ?
import math
abs(math.sqrt(36)) Let's break down the code:
import math
abs(math.sqrt(36))
Step-by-step explanation:
-
math.sqrt(36):- This calculates the square root of 36, which is
6.0. In Python,math.sqrt()always returns a float value.
- This calculates the square root of 36, which is
-
abs():- The
abs()function returns the absolute value of a number. - Since
6.0is already positive,abs(6.0)will simply return6.0.
- The
Conclusion:
The output will be 6.0.
Answer:
(D) 6.0
Correct Answer: D) 6.0
निम्नलिखित कोड का आउटपुट क्या है?
What is the output of following code ?
a=set('abc')
b=set('cd')
print(a^b) Let's break down the code:
a = set('abc') # Converts string 'abc' to a set: {'a', 'b', 'c'}
b = set('cd') # Converts string 'cd' to a set: {'c', 'd'}
print(a ^ b) # The symmetric difference between sets a and b
Explanation:
- Set
ais{'a', 'b', 'c'}. - Set
bis{'c', 'd'}. a ^ bis the symmetric difference of setsaandb, which includes all elements that are in eitheraorbbut not in both.
The elements that are in either a or b but not both are:
'a'and'b'from seta.'d'from setb.
So, the result of a ^ b will be {'a', 'b', 'd'}.
Answer:
(C) {'b', 'a', 'd'}
Correct Answer: C) {'b', 'a', 'd'}
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
from math import factorial
print(math.sqrt(25))
The error occurs because only factorial was imported from the math module, not the whole math module. The code tries to use math.sqrt(25), but math is not available.
To fix it, either import the entire math module:
import math
print(math.sqrt(25))
Or import sqrt directly:
from math import sqrt
print(sqrt(25))
Answer:
(D) Error, the statement should be: print(sqrt(25))
Correct Answer: D) Error, the statement should be: print(sqrt(25))
कथन 1 के लिए उत्तर चुनें.
Choose the answer for statement 1.
import ___________ # statement 1
rec = [ ]
while True:
rn = int(input("Enter"))
nm = input("Enter")
temp = [rn, nm]
rec.append(temp)
ch = input("Enter choice (Y/N)")
if ch.upper == "N":
break
f = open("stud.dat", "____________") #statement 2
__________ .dump(rec, f) #statement 3
_______.close( ) # statement 4 The code involves serializing a list (rec) into a file. The correct module for serializing and deserializing Python objects into a file is pickle.
Explanation:
-
Statement 1: To serialize and deserialize objects, we need to import the
picklemodule. -
Statement 2: The file mode should be
"wb"(write binary) since we are writing serialized data. -
Statement 3: To serialize and save the data to the file, the
pickle.dump()method is used. -
Statement 4: The file should be closed using
f.close().
Correct answer:
(C) pickle
Correct Answer: C) pickle
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
import numpy as np
a = np.array([1.1,2,3])
print(a.dtype) Let's break down the code:
import numpy as np
a = np.array([1.1, 2, 3])
print(a.dtype)
Explanation:
-
Creating the array:
a = np.array([1.1, 2, 3])creates a NumPy array. The array contains a mix offloat(1.1) andint(2 and 3).
-
NumPy Array Type Promotion:
- NumPy automatically promotes the data type of the array to a common type that can hold all the values. Since there is a float (
1.1), NumPy will convert the entire array to thefloat64data type to accommodate the decimal values.
- NumPy automatically promotes the data type of the array to a common type that can hold all the values. Since there is a float (
-
a.dtype:- This returns the data type of the elements in the array. Since the array contains a float, the dtype will be
float64.
- This returns the data type of the elements in the array. Since the array contains a float, the dtype will be
Conclusion:
The output will be float64.
Answer:
(B) float64
Correct Answer: B) float64
कथन 2 के लिए उत्तर चुनें.
Choose the answer for statement 2.
import ___________ # statement 1
rec = [ ]
while True:
rn = int(input("Enter"))
nm = input("Enter")
temp = [rn, nm]
rec.append(temp)
ch = input("Enter choice (Y/N)")
if ch.upper == "N":
break
f = open("stud.dat", "____________") #statement 2
__________ .dump(rec, f) #statement 3
_______.close( ) # statement 4 Let's break down the code for statement 2.
Context:
The code involves writing data (a list of records) into a file, and since we're using serialization (as inferred from the usage of .dump()), the file should be opened in binary write mode.
Explanation:
f = open("stud.dat", "____________"):
Since we're writing binary data (likely usingpickle.dump()), the correct mode to open the file should be"wb", which stands for write binary.
Answer:
(B) wb
Correct Answer: B) wb
आइए मान लें कि 4 बाइनरी में 100 है और 11 1011 है। निम्नलिखित बिटवाइज़ का आउटपुट संचालक क्या है?
Let us assume 4 is 100 in binary and 11 is 1011. What is the output of the following bitwise operators ?
a = 4
b = 11
print(a | b)
print(a >> 2) Let's go through it briefly:
-
Bitwise OR (
|):a = 4(binary:100),b = 11(binary:1011)- OR operation gives
1111in binary, which equals 15 in decimal.
-
Right Shift (
>>):a = 4(binary:100)- Shifting right by 2 positions:
100becomes1, which equals 1 in decimal.
Final Output:
(A) 15 1
Correct Answer: A) 15 1
जब हम सूची ("हैलो") निष्पादित करते हैं तो आउटपुट क्या होता है?
What is the output when we execute list("hello") ?
When we execute list("hello"), Python converts the string "hello" into a list of its individual characters.
Explanation:
"hello"is a string.- Using
list("hello"), we convert the string into a list where each character becomes an element of the list.
So, the result will be:
['h', 'e', 'l', 'l', 'o']
Answer:
(A) ['h', 'e', 'l', 'l', 'o']
Correct Answer: A) ['h', 'e', 'l', 'l', 'o']
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
i = 2
while True:
if i%3 == 0:
break
print(i,end=" " )
i += 2 Let's break down the code:
i = 2
while True:
if i % 3 == 0:
break
print(i, end=" ")
i += 2
Step-by-step execution:
-
i = 2: We start withi = 2. -
First iteration:
i % 3 == 0isFalsebecause2 % 3 == 2.print(i, end=" ")prints2.i += 2makesi = 4.
-
Second iteration:
i = 4, soi % 3 == 0is stillFalsebecause4 % 3 == 1.print(i, end=" ")prints4.i += 2makesi = 6.
-
Third iteration:
i = 6, soi % 3 == 0isTruebecause6 % 3 == 0.- The
breakstatement is executed, and the loop stops.
Conclusion:
The output is 2 4.
Answer:
(B) 2 4
Correct Answer: B) 2 4
निम्नलिखित कोड का आउटपुट क्या होगा?
What will be the output of following code ?
x = ['XX', 'YY']
for i in x
i.lower()
print(x) Let's break down the code step by step:
x = ['XX', 'YY']
for i in x:
i.lower()
print(x)
Explanation:
-
List
x: The listx = ['XX', 'YY']contains two strings:'XX'and'YY'. -
The
forloop:- The loop goes through each element in
x, and for each stringi, it calls thelower()method. However,lower()does not modify the string in place. Strings are immutable in Python, meaning thelower()method returns a new string but does not change the original one.
- The loop goes through each element in
-
The
print(x):- After the loop completes, the list
xis still unchanged becauselower()was applied to each string but its result was not stored back inx.
- After the loop completes, the list
Thus, the list x remains as ['XX', 'YY'].
Answer:
(A) ['XX', 'YY']
Correct Answer: A) ['XX', 'YY']
निम्नलिखित कोड के लिए आउटपुट क्या होगा?
What will be output for the following code ?
import numpy as np
a = np.array([11,2,3])
print(a.min()) Let's break down the code:
import numpy as np
a = np.array([11, 2, 3])
print(a.min())
Explanation:
-
a = np.array([11, 2, 3])creates a NumPy array with the elements[11, 2, 3]. -
a.min()finds the minimum value in the array.
So, the minimum value in the array [11, 2, 3] is 2.
Answer:
(A) 2
Correct Answer: A) 2
कथन 4 के लिए उत्तर चुनें.
Choose the answer for statement 4.
import ___________ # statement 1
rec = [ ]
while True:
rn = int(input("Enter"))
nm = input("Enter")
temp = [rn, nm]
rec.append(temp)
ch = input("Enter choice (Y/N)")
if ch.upper == "N":
break
f = open("stud.dat", "____________") #statement 2
__________ .dump(rec, f) #statement 3
_______.close( ) # statement 4 In this scenario, you're working with the pickle module to serialize data into a file. Let's look at statement 4 in the context of the code:
f = open("stud.dat", "____________") # statement 2
__________ .dump(rec, f) # statement 3
_______.close() # statement 4
Explanation of the code:
- Statement 1 imports the necessary module, likely
picklebecause.dump()is used. - Statement 2 opens the file
stud.datin write-binary mode (wb), allowing us to write binary data to it. - Statement 3 uses
pickle.dump()to serialize thereclist and save it to the filef. - Statement 4 should close the file
fafter writing. To do this, you call.close()on the file objectf.
Thus, statement 4 should close the file object f.
Answer:
(A) f
Correct Answer: A) f
निम्नलिखित छद्म कोड का आउटपुट क्या होगा, जहां ʌ XOR ऑपरेशन का प्रतिनिधित्व करते हैं?
What will be the output of the following pseudo code, where ʌ represent XOR operation ?
Integer a, b, c
Set b = 5, a = 1
c = a ^ b
Print c Sure! Here's a simple breakdown:
- a = 1 and b = 5.
- In binary:
a = 1→0001b = 5→0101
- XOR operation (
^):- Compare bits:
0001 ^ 0101 - Result:
0100(binary) 0100in decimal = 4
- Compare bits:
Answer:
(A) 4
Correct Answer: A) 4
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here") Sure! Here's a simple breakdown:
- The
forloop runs fromi = 0toi = 9. - When
ireaches 5, thebreakstatement stops the loop. - The numbers
0 1 2 3 4are printed because the loop ends beforeireaches 5. - The
elseafter the loop is not executed because the loop was stopped withbreak.
Output:
(C) 0 1 2 3 4
Correct Answer: C) 0 1 2 3 4
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
a = 15
b = 6
print(a and b)
print(a or b) Let's break down the code and the logic behind it:
a = 15
b = 6
print(a and b)
print(a or b)
Explanation:
-
a and b:- In Python, the
andoperator returns the second operand if the first operand is truthy (non-zero). - Since
a = 15(a non-zero value, which is truthy), the result ofa and bisb, which is 6.
- In Python, the
-
a or b:- The
oroperator returns the first truthy operand it encounters. - Since
a = 15is truthy, the result ofa or bisa, which is 15.
- The
Output:
(C) 6 15
Correct Answer: C) 6 15
यदि उपयोगकर्ता ने 55 दर्ज किया है तो आउटपुट क्या है?
What is the output, if user has entered 55 ?
a=input("Enter a number")
print(type(a)) In Python, the input() function always returns a value as a string. So, even if the user enters a number like 55, the input is treated as a string.
Explanation:
a = input("Enter a number"): The value entered by the user (in this case, 55) is stored as a string.print(type(a)): This will print the type of the variablea, which is a string (str), not an integer or float.
Output:
(D) str
Correct Answer: D) str
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 largest number.
Else
Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop Sure! Here's a simple explanation:
- We are given
a = 5,b = 8, andc = 6. - The algorithm first checks if
a > b, buta(5) is not greater thanb(8). - Since
ais not greater thanb, the algorithm moves to theelsepart, which checks ifb > c. - Since
b(8) is greater thanc(6), it prints "b is the largest number".
Output: (A) b is the largest number
Correct Answer: A) b is the largest number
निम्नलिखित कोड का आउटपुट क्या है?
What is the output of following code ?
a1={1:"A",2:"B",3:"C"}
b1={4:"D",5:"E"}
b1.update(a1)
print(b1) Sure! Here's a concise explanation:
-
We have two dictionaries:
a1 = {1: "A", 2: "B", 3: "C"}b1 = {4: "D", 5: "E"}
-
The
update()method adds the items froma1tob1. -
After
b1.update(a1),b1will include all key-value pairs from both dictionaries.
So, the final result of b1 will be:
{4: 'D', 5: 'E', 1: 'A', 2: 'B', 3: 'C'}
Output: (A)
Correct Answer: A) {4: 'D', 5: 'E', 1: 'A', 2: 'B', 3: 'C'}
कौन सा कथन एक फ़ाइल (फ़ाइल ऑब्जेक्ट „f‟) से 5 अक्षर पढ़ेगा?
Which statement will read 5 characters from a file(file object „f‟) ?
The correct answer is:
(B) f.read(5)
Explanation:
f.read(5)reads exactly 5 characters from the file. The number5specifies the number of characters to read from the file.f.read()without a number will read the entire file or until the end of the file.f.reads(5)is incorrect and will raise an error since there is noreadsmethod.
Output:
(B) f.read(5)
Correct Answer: B) f.read(5)
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
from math import *
ceil(3.4) The correct answer is:
(A) 4
Explanation:
- The
ceil()function from themathmodule returns the smallest integer greater than or equal to the given number. - For
ceil(3.4), the smallest integer greater than or equal to3.4is4.
So, the output of the code ceil(3.4) is 4.
Output:
(A) 4
Correct Answer: A) 4
निम्नलिखित ऑब्जेक्ट का डेटा प्रकार क्या है?
What is the data type of following object ?
A = [5,‟abc‟,3.2,6] The correct answer is:
(C) list
Explanation:
- The object
A = [5, 'abc', 3.2, 6]is enclosed in square brackets[], which denotes a list in Python. - A list can hold items of various data types, such as integers, strings, and floating-point numbers, as seen in the example.
Output:
(C) list
Correct Answer: C) list
निम्नलिखित कोड का आउटपुट क्या है?
What is the output of following code ?
A=[[1,2,3],
[4,5,6],
[7,8,9]]
print(A[1][:]) The correct answer is:
(B) [4, 5, 6]
Explanation:
Ais a 2D list (a list of lists), whereA[1]refers to the second list (since indexing starts from 0), which is[4, 5, 6].- The
[:]slice operator is used to copy the entire list at index1. So,A[1][:]gives the list[4, 5, 6].
Output:
(B) [4, 5, 6]
Correct Answer: B) [4, 5, 6]
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
import numpy as np
a = np.array([[1,2,3],[4,5,6],[7,8,9]])
print(a.shape) The correct answer is:
(B) (3, 3)
Explanation:
- The array
ais a 2D NumPy array with 3 rows and 3 columns:[[1, 2, 3], [4, 5, 6], [7, 8, 9]] - The
.shapeattribute of a NumPy array returns a tuple that gives the dimensions of the array (rows, columns). - In this case, the shape of the array is
(3, 3), meaning 3 rows and 3 columns.
Output:
(B) (3, 3)
Correct Answer: B) (3, 3)
print((-3)** 2) का आउटपुट क्या है?
What is the output of print((-3)** 2) ?
The correct answer is:
(D) 9
Explanation:
- In Python, the expression
(-3)**2means that the negative number-3is raised to the power of2. - The exponentiation operator
**has higher precedence than the negative sign, so-3is treated as(-3)and then squared. - Squaring
-3gives9because: (−3)×(−3)=9(-3) \times (-3) = 9
Output:
(D) 9
Correct Answer: D) 9
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
def say(message, times = 1):
print(message * times)
say('Hello')
say('World', 5)
The correct answer is:
(A) Hello WorldWorldWorldWorldWorld
Explanation:
- In the function
say(message, times=1), the default value fortimesis1. - When
say('Hello')is called, it prints the message'Hello'only once becausetimesis defaulted to 1. - When
say('World', 5)is called, the message'World'is printed 5 times because thetimesparameter is explicitly set to 5.
Output:
(A) Hello WorldWorldWorldWorldWorld
Correct Answer: A) Hello WorldWorldWorldWorldWorld
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
import numpy as np
a = np.array([[1,2,3]])
print(a.ndim) The correct answer is:
(B) 2
Explanation:
- In the code,
ais a NumPy array created with the shape[[1, 2, 3]], which represents a 2D array with 1 row and 3 columns. a.ndimreturns the number of dimensions of the array.- Since
ais a 2D array (1 row and 3 columns),a.ndimwill be 2.
Output:
(B) 2
Correct Answer: B) 2
निम्नलिखित कोड खंड क्या प्रिंट करेगा?
What will following code segment print ?
a = True
b = False
c = False
if a or b and c:
print "HELLO"
else:
print "hello" The correct answer is:
(A) HELLO
Explanation:
- The expression
a or b and cevaluates the logical conditions. - Python evaluates
andbeforeor. So, the expression is evaluated asa or (b and c). - Since
b and cisFalse(because bothbandcareFalse), the condition becomesa or False, which isTrue or False, which results inTrue. - Since the condition is
True, theifblock is executed, and it prints "HELLO".
Output:
(A) HELLO
Correct Answer: A) HELLO
निम्नलिखित में से कौन सा नंबर निम्नलिखित कोड द्वारा कभी भी उत्पन्न नहीं किया जा सकता है:
Which of the following number can never be generated by the following code :
random.randrange(0, 50) The correct answer is:
(D) 50
Explanation:
The random.randrange(start, stop) function generates a random number in the range from start to stop - 1, i.e., it includes start but excludes stop.
- In this case,
random.randrange(0, 50)will generate a number between 0 and 49 (inclusive of 0 and exclusive of 50). - Therefore, 50 can never be generated by this code.
Output:
(D) 50
Correct Answer: D) 50
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
x = 'abcd'
for i in range(x):
print(i) The answer is (C) error.
Reason:
The code for i in range(x): will throw an error because x is a string ('abcd'), and range() expects an integer. You can't pass a string to range().
Fix:
You need to use len(x) to get the length of the string:
for i in range(len(x)):
print(i)
This will print the indices (0, 1, 2, 3). But as the code is written, it will result in an error.
Correct Answer: C) error
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
y = "I love Python"
y[3] = 's'
print(y) निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
min(max(False,-3,-4), 2,7) निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
t=(2, 3, 4, 3.5, 5, 6)
print(sum(t) + t.count(2)) Let's break down the code and understand it step by step:
Given:
t = (2, 3, 4, 3.5, 5, 6)
-
sum(t): This function will return the sum of all the elements in the tuple
t.- 2 + 3 + 4 + 3.5 + 5 + 6 = 23.5
-
t.count(2): This function will count how many times the number
2appears in the tuplet.- The number
2appears once in the tuple.
- The number
-
Now, we add these two results:
- sum(t) = 23.5
- t.count(2) = 1
So, 23.5 + 1 = 24.5
Thus, the correct answer is (C) 24.5.
Correct Answer: C) 24.5
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
def sayHello():
print("Hello World!‟)
sayHello()
sayHello() The code has a small typo in the print statement. Specifically, the closing quotation mark for the string "Hello World!" is incorrectly written as a special character ‟ instead of a standard double quote ".
Here’s the corrected version of the code:
def sayHello():
print("Hello World!")
sayHello()
sayHello()
Now, if the code is corrected, the output will be:
Hello World!
Hello World!
Correct Answer: (A) Hello World! Hello World!
Correct Answer: A) Hello World! Hello World!
निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
a = 50
b = a= a*5
print(b) Let's break down the code:
a = 50
b = a = a * 5
print(b)
- Initially,
a = 50. - Then
b = a = a * 5:- The expression
a * 5is evaluated first, which results in50 * 5 = 250. - This result is assigned to
a, soabecomes250. - Simultaneously,
bis also assigned the value ofa, which is now250.
- The expression
- Finally,
print(b)outputs the value ofb, which is250.
So, the output of the code is:
Answer: (A) 250
Correct Answer: D) Syntax Error
निम्नलिखित कोड का उद्देश्य क्या है?
What is the purpose of the following code ?
import numpy as np
z=[1,2,3]
y=np.array(z) The code provided:
import numpy as np
z = [1, 2, 3]
y = np.array(z)
Explanation:
z = [1, 2, 3]: This creates a regular Python list with elements 1, 2, and 3.y = np.array(z): This converts the Python listzinto a NumPy array and stores it iny.
Thus, the purpose of the code is to convert the list z into a NumPy array.
Answer: (A) to convert z to array
Correct Answer: A) to convert z to array