🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X

O Level Python Paper January 2021

Question: 1 Report Error

निम्नलिखित पायथन प्रोग्राम का आउटपुट खोजें।

Find the output of following Python Programs.

a= “Meetmeatafterparty”
b= 13
print a+b
A)
B)
C)
D)
Explanation
The correct answer is (C) error in code.
In the given Python program, there are two issues:
  1. The variable a is assigned a string value “Meetmeatafterparty”, but it is not enclosed in quotes. This will result in a syntax error.
  2. The variable b is assigned an integer value 13.
The print statement print a + b attempts to concatenate the string value of a with the integer value of b, which is not allowed in Python. This will result in a TypeError.
Therefore, the program will not execute correctly, and the output will be an error in the code.
    • पायथन में एक स्ट्रिंग (String) और एक पूर्णांक (Integer) को + ऑपरेटर का उपयोग करके सीधे नहीं जोड़ा जा सकता। यह TypeError देगा।

Correct Answer: C) error in code


Question: 2 Report Error

निम्नलिखित पायथन प्रोग्राम का आउटपुट खोजें।

Find the output of the following Python programs.

class Acc: 
	def __init__(self, id): 
		self.id = id
		id = 555

acc = Acc(111) 
print (acc.id) 
A)
B)
C)
D)
Explanation
  • The __init__ method takes a parameter id, and assigns that value to the instance attribute self.id.
  • The line id = 555 modifies the local id variable in the constructor, but does not affect the instance variable self.id.
  • When you print acc.id, it will print the value that was passed into the constructor, which is 111.

Output:

 
111 

Explanation:

  • The id inside the __init__ method is a local variable. Changing it doesn't affect the instance variable self.id.
  • So, the value of self.id remains as 111 even though id = 555 is set within the constructor.self.id = id इंस्टेंस वेरिएबल को असाइन करता है। अगली लाइन id = 555 केवल एक लोकल वेरिएबल को बदलती है, क्लास के
  • self.id को नहीं। इसलिए acc.id का मान 111 ही रहेगा।

Correct Answer: A) 111


Question: 3 Report Error

निम्नलिखित में से कौन सा एक अमान्य चर है?

Which of the following is an invalid variable?

A)
B)
C)
D)
Explanation

The invalid variable in the list is:

(D) 1st_string

In most programming languages, variable names cannot start with a number. So, 1st_string is an invalid variable name because it starts with a digit (1).

The other options are valid variable names:

  • (A) my_string_1: This is valid.
  • (B) foo: This is valid.
  • (C) __: This is valid, though it's often used for special purposes in some languages (like Python). 
    • पायथन में वेरिएबल का नाम कभी भी अंक (digit) से शुरू नहीं हो सकता।

Correct Answer: D) 1st_string


Question: 4 Report Error

निम्नलिखित पायथन प्रोग्राम का आउटपुट खोजें।

Find the output of the following Python programs.

x=['ab','cd']
for i in x:
     i.upper()
print(x)
A)
B)
C)
D)
Explanation
  • The upper() method: The upper() method returns a new string with all characters in uppercase. However, strings in Python are immutable, meaning that calling upper() on a string does not modify the original string in place. Instead, it returns a new string. In the loop, the result of i.upper() is not assigned to any variable or used, so it has no effect on the original list x.

  • The loop: The loop iterates through each string in the list x. For each string, i.upper() is called, but since the result is not used, the strings in the list x remain unchanged.

  • Printing the list x: After the loop finishes, the list x remains as ['ab', 'cd'] because no modifications have been made to it.

  • स्ट्रिंग के मेथड जैसे upper() मूल स्ट्रिंग को नहीं बदलते (क्योंकि स्ट्रिंग Immutable होती है)। जब तक आप i = i.upper() नहीं करते और उसे वापस लिस्ट में नहीं डालते, लिस्ट वैसी ही रहेगी।

Correct Answer: C) ['ab','cd']


Question: 5 Report Error

निम्नलिखित प्रोग्राम का आउटपुट क्या है?

What is the output of the following program?

a = 2
b= '3.77'
c = - 8 
str1= '{0:4f} {0:3d} {2} {1}'. format(a, b, c) 
print(str1) 
A)
B)
C)
D)
Explanation

The given program formats the string using the format() method:

  • {0:4f}: Formats a (which is 2) as a float with 4 decimal places → 2.0000
  • {0:3d}: Formats a (which is 2) as an integer with a width of 3 → 2
  • {2}: Prints c (which is -8)
  • {1}: Prints b (which is '3.77')

So, the output is:

(A) 2.0000 2 -8 3.77

{0:4f} संख्या को फ्लोट में बदलता है (डिफ़ॉल्ट 6 डेसिमल), {0:3d} उसे इंटीजर की तरह स्पेस के साथ दिखाता है। (नोट: प्रश्न के विकल्पों में डेसिमल की संख्या में अंतर हो सकता है, लेकिन तर्क यही है)।

Correct Answer: A) 2.0000 2 -8 3.77


Question: 6 Report Error

निम्नलिखित पायथन प्रोग्रामों का आउटपुट पता करें:

Find out the output of the following Python programs:

def gfg(x,l=[]):
    for i in range(x):
        l.append(i*i)
    print(l)
gfg(2)
A)
B)
C)
D)
Explanation

Let's analyze the given Python code step by step:

def gfg(x, l=[]):
    for i in range(x):
        l.append(i * i)
    print(l)

gfg(2)
  1. Function gfg:

    • It takes two parameters: x and l. l has a default value of an empty list [].
    • Inside the function, a loop runs from 0 to x-1 (inclusive). In each iteration, it appends i*i (the square of i) to the list l.
  2. Calling gfg(2):

    • x = 2 and l uses the default value [] (an empty list).
    • The loop will run for i = 0 and i = 1:
      • When i = 0: 0*0 = 0, so 0 is appended to the list.
      • When i = 1: 1*1 = 1, so 1 is appended to the list.
  3. Final result: After the loop, the list l will contain [0, 1] and that will be printed.

Output:

(B) [0, 1]

Explanation:

  • Since the list l starts empty and the loop runs twice (for i = 0 and i = 1), the final list becomes [0, 1].
    • range(2) का मतलब है 0 और 1। i*i करने पर 0*0=0 और 1*1=1 लिस्ट में जुड़ेंगे।

Correct Answer: B) [0, 1]


Question: 7 Report Error

मान लीजिए t=(1, 2, 4, 3), तो निम्नलिखित में से कौन सा गलत है?

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

A)
B)
C)
D)
Explanation

Let's break down the options for the given tuple t = (1, 2, 4, 3):

  • (A) print(t[3]): This is correct. Indexing starts from 0, so t[3] refers to the fourth element, which is 3. This will print 3.

  • (B) t[3] = 45: This is incorrect. Tuples are immutable in Python, meaning their elements cannot be changed after creation. Attempting to modify t[3] will result in a TypeError.

  • (C) print(max(t)): This is correct. The max() function returns the largest element in the tuple. Here, the largest element is 4, so it will print 4.

  • (D) print(len(t)): This is correct. The len() function returns the number of elements in the tuple. Here, the length of t is 4, so it will print 4.

Answer:

The incorrect statement is:

(B) t[3] = 45

टपल (Tuple) Immutable होते हैं, यानी एक बार बनने के बाद उनके तत्वों को बदला नहीं जा सकता।

Correct Answer: B) t[3]=45


Question: 8 Report Error

निम्नलिखित पायथन कोड का आउटपुट क्या होगा?

What will be the output of the following Python code?

t1 = (1, 2, 4, 3)
t2 = (1, 2, 3, 4)
print(t1<t2)
A)
B)
C)
D)
Explanation

The given Python code is:

t1 = (1, 2, 4, 3)
t2 = (1, 2, 3, 4)
print(t1 < t2)

Step-by-Step Explanation:

  • Tuples in Python are ordered, immutable collections of elements.
  • When comparing two tuples, Python compares them element by element from left to right.
  • If the first elements are equal, it moves to the next element and so on.
  • If one tuple is smaller than the other at any point, the comparison is decided based on that element.

Now, let's compare t1 and t2:

  • t1 = (1, 2, 4, 3)
  • t2 = (1, 2, 3, 4)

Comparing element by element:

  1. The first elements (1 in both t1 and t2) are equal, so we move to the next element.
  2. The second elements (2 in both t1 and t2) are also equal, so we move to the next element.
  3. The third elements are different: t1 has 4, while t2 has 3.
    • Since 4 > 3, t1 is not less than t2.

Therefore, the result of the comparison t1 < t2 is False.

Answer:

(B) False

पायथन टपल्स की तुलना पहले तत्व से शुरू करता है। यहाँ $1=1$ और $2=2$ है, लेकिन तीसरे स्थान पर $4 < 3$ गलत है, इसलिए परिणाम False आएगा

Correct Answer: B) False


Question: 9 Report Error

निम्नलिखित में से कौन सा कथन recursion के बारे में गलत है?

Which of the following statements is false about recursion ?

A)
B)
C)
D)
Explanation

यह गलत है। एक रिकर्सिव फ़ंक्शन बिना कुछ रिटर्न किए भी प्रिंट जैसा कार्य कर सकता है (जैसे ट्री ट्रैवर्सल)। हालाँकि, बेस केस होना अनिवार्य है।

Correct Answer: D) Every recursive function must have a return value (प्रत्येक पुनरावर्ती फ़ंक्शन का एक रिटर्न मान होना चाहिए)


Question: 10 Report Error

निम्नलिखित पायथन कोड का आउटपुट क्या होगा?

What will be the output of the following Python code ?

import functools
l=[1, 2, 3, 4, 5]
m=functools.reduce(lambda x, y:x if x>y else y, l)
print(m)
A)
B)
C)
D)
Explanation

The code uses functools.reduce() to find the largest number in the list l = [1, 2, 3, 4, 5].

  • The lambda x, y: x if x > y else y function compares two numbers at a time and keeps the larger one.
  • After comparing all elements, the largest number 5 is stored in m.

Output:

(D) 5reduce फ़ंक्शन यहाँ दी गई लिस्ट में सबसे बड़ी संख्या (Max) ढूँढ रहा है।

Correct Answer: D) 5


Question: 21 Report Error

निम्नलिखित पायथन प्रोग्राम का आउटपुट ____ है

The output of following Python program is _____.

r = lambda q: q*2
s = lambda q: q * 3
x = 2
x = r(x)
x = s(x) 
x = r(x)
print x
A)
B)
D)
Explanation

Let's break down the given Python code step by step:

r = lambda q: q * 2
s = lambda q: q * 3
x = 2
x = r(x)
x = s(x)
x = r(x)
print(x)

Step-by-Step Explanation:

  1. Define the lambdas:

    • r = lambda q: q * 2: This lambda function doubles the input.
    • s = lambda q: q * 3: This lambda function triples the input.
  2. Initial value of x:

    • x = 2
  3. Apply r(x):

    • x = r(x) means x = 2 * 2 = 4. Now, x is 4.
  4. Apply s(x):

    • x = s(x) means x = 4 * 3 = 12. Now, x is 12.
  5. Apply r(x) again:

    • x = r(x) means x = 12 * 2 = 24. Now, x is 24.
  6. Final output:

    • print(x) prints the final value of x, which is 24.

Answer:

(B) 24

$x=2 \rightarrow r(2)=4 \rightarrow s(4)=12 \rightarrow r(12)=24$.

Correct Answer: B) 24


Question: 22 Report Error

आइए निम्नलिखित पायथन कोड पर विचार करें, इस कोड का आउटपुट है

Let consider the following Python code. The output of this code is ____

a = True
b = False 
c = False 
if a or b and c:
    print("TRUE")
else:
    print("FALSE") 
A)
B)
C)
D)
Explanation

Let's analyze the given Python code:

a = True
b = False
c = False
if a or b and c:
    print("TRUE")
else:
    print("FALSE")

Step-by-Step Explanation:

  1. Variables:

    • a = True
    • b = False
    • c = False
  2. Condition in the if statement:

    • The expression a or b and c involves both the logical or and and operators.
    • Operator Precedence: In Python, and has higher precedence than or. So, b and c is evaluated first.
  3. Evaluate b and c:

    • b and c evaluates as False and False, which is False.
  4. Evaluate a or (b and c):

    • Now the condition becomes a or False, which is True or False, which is True.
  5. Result:

    • Since the condition evaluates to True, the code inside the if block is executed, so "TRUE" is printed.

Answer:

(A) TRUE

if a or b and c में or की वजह से यदि a (True) है, तो पूरा एक्सप्रेशन True हो जाता है

Correct Answer: A) TRUE


Question: 23 Report Error

पुनरावर्ती फ़ंक्शन आमतौर पर गैर-पुनरावर्ती फ़ंक्शन की तुलना में _______ मेमोरी स्थान लेते हैं।

Recursive functions usually take ________ memory space than non-recursive function.

A)
B)
C)
D)
Explanation
    • रिकर्शन 'Stack' का उपयोग करता है, इसलिए यह अधिक मेमोरी लेता है।

Correct Answer: A) MORE


Related Papers



















































Latest Updates