O Level Python Paper January 2022
इनमें से कौन सा कोर डेटा प्रकार नहीं है?
Which of these is not a core data type ?
Lists, Dictionary, और Tuples पायथन के Built-in core data types हैं। जबकि Class का उपयोग उपयोगकर्ता द्वारा परिभाषित (User-defined) डेटा प्रकार या ऑब्जेक्ट बनाने के लिए किया जाता है।
Correct Answer: D) Class
नीचे दिया गया ऑब्जेक्ट किस डेटा प्रकार का है?
What data type is the object below?
L=[1, 23, 'hello', 1] The given object is:
L = [1, 23, 'hello', 1]
Explanation:
- The object
Lis enclosed in square brackets ([]), which denotes a list in Python. - A list in Python is an ordered collection that can contain items of different data types, including integers, strings, and others.
Answer:
(A) Lists
-
-
पायथन में स्क्वायर ब्रैकेट
[]का उपयोग लिस्ट को दर्शाने के लिए किया जाता है। लिस्ट में अलग-अलग प्रकार के डेटा (जैसे यहाँ integer और string) रखे जा सकते हैं।
-
Correct Answer: A) Lists
निम्नलिखित में से कौन सा फ़ंक्शन पायथन में स्ट्रिंग को फ्लोट में परिवर्तित करता है?
Which of the following functions converts a string to a float in python ?
-
-
float()फ़ंक्शन किसी स्ट्रिंग या संख्या को फ्लोटिंग-पॉइंट (दशमलव) संख्या में बदलता है।
-
Correct Answer: C) float(x)
निम्नलिखित प्रोग्राम का आउटपुट क्या है?
What is the output of the following program ?
def myfunc(a):
a=a+2
a=a*2
return a
print myfunc(2)
Let's analyze the given Python code:
def myfunc(a):
a = a + 2
a = a * 2
return a
print(myfunc(2))
Step-by-Step Explanation:
-
Function Definition:
- The function
myfunc(a)takes one argumenta. - Inside the function:
- First,
a = a + 2increasesaby 2. - Then,
a = a * 2doubles the new value ofa.
- First,
- Finally, the function returns the value of
a.
- The function
-
Function Call:
- The function is called with
a = 2, so:a = 2 + 2→a = 4a = 4 * 2→a = 8
- The function then returns
8.
- The function is called with
-
Output:
- The
print(myfunc(2))will print the returned value, which is8.
- The
Answer:
(A) 8
-
प्रक्रिया: $a = 2 \rightarrow a = 2 + 2 = 4 \rightarrow a = 4 * 2 = 8$।
Correct Answer: A) 8
अभिव्यक्ति 3*1**3 का आउटपुट क्या है?
What is the output of the expression : 3*1**3 ?
Let's break down the expression:
3 * 1 ** 3
Step-by-Step Explanation:
-
Operator Precedence:
- The
**operator (exponentiation) has higher precedence than multiplication (*). - So, the expression is evaluated as:
3 * (1 ** 3).
- The
-
Evaluate
1 ** 3: -
1 ** 3means1raised to the power of3, which is1.
-
Evaluate the final multiplication:
- Now the expression becomes
3 * 1, which equals3.
- Now the expression becomes
Answer:
(C) 3
-
पायथन में घातांक (Exponentiation
**) की प्राथमिकता गुणा (*) से अधिक होती है। -
गणना: $3 * (1 ** 3) \rightarrow 3 * 1 = 3$।
Correct Answer: C) 3
निम्नलिखित प्रोग्राम का आउटपुट क्या है?
What is the output of the following program ?
i=0
while i<3:
print(i)
i+=1
else:
print 0 The program prints the values of i from 0 to 2 inside the while loop, and then prints 0 from the else block after the loop finishes.
Output:
(B) 0 1 2 0
while लूप 0, 1, 2 प्रिंट करेगा। जब कंडीशन i < 3 गलत हो जाएगी, तब else ब्लॉक चलेगा और 0 प्रिंट करेगा
Correct Answer: B) 0 1 2 0
निम्नलिखित प्रोग्राम का आउटपुट क्या है?
What is the output of the following program ?
print "Hello World"[::-1]
The given Python code is:
print "Hello World"[::-1]
Explanation:
"Hello World"is a string.[::-1]is a slicing operation that reverses the string.- The slice notation
[::-1]means "take the string and step backwards by 1, effectively reversing it."
- The slice notation
So, reversing "Hello World" gives: "dlroW olleH"
Output:
(A) dlroWolleH
Note: In Python 3, print requires parentheses, so the correct code would be print("Hello World"[::-1]). However, based on the given code, it seems to be Python 2, where print doesn't need parentheses.
[::-1] स्लाइसिंग ऑपरेटर है जो स्ट्रिंग को पूरी तरह से उलट (Reverse) देता है
Correct Answer: A) dlroWolleH
एक ऐसा फ़ंक्शन दिया गया है जो कोई मान नहीं लौटाता है, शेल पर निष्पादित होने पर क्या मान दिखाया जाता है?
Given a function that does not return any value, what value is shown when executed at the shell ?
पायथन में यदि कोई फ़ंक्शन return स्टेटमेंट का उपयोग नहीं करता है, तो वह डिफ़ॉल्ट रूप से None ऑब्जेक्ट लौटाता है
Correct Answer: D) None
निम्नलिखित प्रोग्राम का आउटपुट क्या है?
What is the output of the following program ?
print 0.1+0.2==0.3 Let's analyze the given Python program:
print 0.1 + 0.2 == 0.3
Explanation:
- In Python, floating-point numbers like
0.1,0.2, and0.3cannot always be represented precisely due to the way floating-point arithmetic works in computers. - When you compute
0.1 + 0.2, it may result in a value slightly different from0.3because of precision errors in floating-point representation.
Specifically:
0.1 + 0.2results in0.30000000000000004, which is not exactly equal to0.3.
Thus, the expression 0.1 + 0.2 == 0.3 evaluates to False.
Output:
(B) False
यह फ्लोटिंग-पॉइंट अंकगणित की सीमा के कारण होता है। बाइनरी में $0.1$ और $0.2$ को सटीक रूप से नहीं दर्शाया जा सकता, जिससे $0.1 + 0.2$ का मान लगभग $0.30000000000000004$ आता है।
Correct Answer: B) False
एक स्ट्रिंग s="Welcome" दी गई है, निम्नलिखित में से कौन सा कोड गलत है?
Given a string s="Welcome", which of the following code is incorrect ?
Here’s a quick breakdown:
- (A)
s[0]is correct; it prints the first character"W". - (B)
s.lower()is correct; it converts the string to"welcome". - (C)
s[1] = 'r'is incorrect because strings are immutable in Python (you can't change individual characters). - (D)
s.strip()is correct; it removes any leading or trailing spaces (if any).
Answer:
(C) s[1] = 'r' is incorrect.
-
-
पायथन में स्ट्रिंग्स Immutable (अपरिवर्तनीय) होती हैं। आप किसी स्ट्रिंग के एक विशिष्ट कैरेक्टर को असाइनमेंट के ज़रिए नहीं बदल सकते।
-
Correct Answer: C) s[1]='r'