O Level Python Paper July 2024
कोड की कौन सी पंक्ति 'grapes' की key और 15 के value के साथ fruits dictionary में एक आइटम को सही ढंग से जोड़ती है?
Which line of code correctly adds an item to the fruits dictionary with a key of ‘grapes’ and a value of 15?
fruits = {'apples': 1, 'bananas': 4, 'pears': 17, 'oranges': 14} To add an item to the fruits dictionary with the key 'grapes' and the value 15, you should use the following syntax:
fruits['grapes'] = 15
This correctly adds the key 'grapes' with the value 15 to the dictionary.
Answer: (B) fruits['grapes'] = 15
Correct Answer: B) fruits['grapes'] = 15
नीचे दिए गए कोड का आउटपुट क्या है?
What is the output of below code?
print(3-2*2*3+99/11)
The expression is:
Step 1: Follow the order of operations (PEMDAS/BODMAS).
- Parentheses
- Exponents
- Multiplication and Division (from left to right)
- Addition and Subtraction (from left to right)
Step 2: Break down the expression.
-
First, handle the multiplication and division.
- 2 * 2 = 4
- 4 * 3 = 12
- 99 / 11 = 9
Now the expression becomes:
-
Now, perform the addition and subtraction from left to right:
- 3 - 12 = -9
- -9 + 9 = 0
Final result: 0
Correct Answer: A) 0.0
क्या पायथन कोड संकलित या व्याख्यायित है?
Is python code compiled or interpreted?
Python is an interpreted language, but it has some features of compiled languages as well. Here's how it works:
1. Python as an Interpreted Language:
- Interpreter: Python code is executed by an interpreter, which means the source code is executed line-by-line, at runtime, rather than being converted into machine code ahead of time.
- This makes Python easier to debug and allows for quick testing and prototyping since you can run the code directly without a separate compilation step.
2. How Python Executes Code:
- Step 1: When you run a Python program, the Python interpreter first converts the code into an intermediate form called bytecode.
- Step 2: This bytecode is then executed by the Python Virtual Machine (PVM).
The bytecode is a lower-level representation of your code, which can be executed efficiently by the interpreter. This is why Python is sometimes said to be compiled to bytecode, but it is still ultimately interpreted when run.
3. What Happens Under the Hood:
- When you run a Python script, the interpreter performs the following:
- Parsing: The Python source code (
.pyfile) is parsed and translated into an intermediate bytecode (.pycor.pyofiles). - Execution: This bytecode is then executed by the Python Virtual Machine (PVM), which is the interpreter itself.
- Parsing: The Python source code (
Correct Answer: B) Both compiled and interpreted.
एल्गोरिथम का वह भाग जिसे निश्चित संख्या में बार-बार दोहराया जाता है, को इस प्रकार वर्गीकृत किया गया है
Part of algorithm which is repeated for fixed number of times is classified as
Part of an algorithm which is repeated for the fixed number of times is classified as Iteration. In this, a set of instructions are repeated again and again. In computer programming, a loop is a kind of iteration in which instructions sequence is executed repeatedly.
Correct Answer: A) Iteration
फ़ंक्शन pow(x,y,z) का मूल्यांकन इस प्रकार किया जाता है:
The function pow(x,y,z) is evaluated as:
The pow(x, y, z) function in Python is evaluated as:
(xy) % z
This means that it computes xyx^y (x raised to the power y), and then takes the result modulo z.
So the correct answer is:
(C) (xy) % z
Correct Answer: C) (x**y) % z
________एक डेटा फ़ाइल है।
________is a data file.
A data file can refer to both binary files and text files, as both types of files are used to store data. The difference between the two lies in how the data is encoded and interpreted:
-
Text File: A file that contains human-readable data in a plain text format (e.g.,
.txt,.csv). Data is stored as characters that can be easily interpreted and read by both humans and machines. -
Binary File: A file that contains data in a format that is not human-readable. It can store any kind of data (e.g., images, videos, executable files) in binary format (e.g.,
.jpg,.exe,.mp3). The data is represented in 0s and 1s and typically requires specific software or tools to interpret.
Correct Answer: C) Both Binary File and Text file
कौन सा कथन फ़ाइल से एक पंक्ति लौटाएगा (फ़ाइल ऑब्जेक्ट 'f‟ है)?
Which statement will return one line from a file (file object is 'f‟) ?
- When you call
f.readline(), it reads the next line from the file objectf. It reads until it reaches the end of the line, including the newline character (\n), but it does not return the newline character at the end of the string. - If the end of the file is reached,
f.readline()returns an empty string ('').
Correct Answer: B) f.readline()
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following ?
import sys
sys.stdout.write('Welcome\n')
sys.stdout.write('All\n') -
The first line,
sys.stdout.write('Welcome\n'), will print "Welcome" followed by a newline character (\n), meaning it will move the cursor to the next line. -
The second line,
sys.stdout.write('All\n'), will print "All" followed by a newline as well.
Correct Answer: A) Welcome All
बाइनरी फ़ाइल डेटा को पढ़ने के लिए ___________ फ़ंक्शन का उपयोग किया जाता है।
To read binary files data ___________ function is used.
In Python, the method load() is typically associated with deserializing or loading data from a file or another storage medium into a Python object. It is most commonly used with libraries like json, pickle, or yaml for reading data from files.
Correct Answer: D) load()
निम्नलिखित स्यूडोकोड का आउटपुट क्या होगा, जहां ^ XOR ऑपरेशन का प्रतिनिधित्व करता है?
What will be the output of the following pseudocode, where ^ represent XOR operation?
Integer a, b, c
Set b=5,a=1
c=a^b
print c Sure! Here's a quick explanation:
- a = 1 in binary:
0001 - b = 5 in binary:
0101
XOR operation (^) compares bits:
- 0 ^ 0 = 0
- 0 ^ 1 = 1
- 1 ^ 0 = 1
- 1 ^ 1 = 0
When we XOR 0001 and 0101, the result is 0100, which is 4 in decimal.
Thus, the output is 4.
Answer: (A) 4.
Correct Answer: A) 4
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code?
>>>t1 = (1, 2, 4, 3)
>>>t2 = (1, 2, 3, 4)
>>>t1 < t2 The output will be (B) False.
Explanation:
- Python compares tuples element by element.
- In this case,
t1 = (1, 2, 4, 3)andt2 = (1, 2, 3, 4). - Python first compares
1with1(equal), then2with2(equal). - Next, it compares
4(fromt1) with3(fromt2). Since4 > 3, Python concludest1 > t2.
So, the comparison t1 < t2 is False.
Correct Answer: B) False
यदि list1=[10,20,30], तो ऑपरेशन list1*2 _____ लौटाता है।
if list1=[10,20,30], then operation list1*2 returns _____.
The correct answer is (A) [10,20,30,10,20,30].
Explanation:
- When you multiply a list by a number in Python, the list repeats that many times.
- In this case,
list1 = [10, 20, 30]and you performlist1 * 2. - This operation results in the list being repeated twice, so the output will be
[10, 20, 30, 10, 20, 30].
Correct Answer: A) [10,20,30,10,20,30]
एक स्ट्रिंग x=”hello” दी गई है तो x.count('l') का आउटपुट क्या है?
Given a string x=”hello” What is the output of x.count(‘l’) ?
The correct answer is (A) 2.
Explanation:
- The
count()method in Python returns the number of times a specified value appears in the string. - In the string
x = "hello", the character'l'appears twice. - Therefore,
x.count('l')will return 2.
Correct Answer: A) 2
निम्नलिखित में से कौन dictionary में कुंजी "tiger" के लिए कुंजी-मूल्य जोड़ी को हटा देगा?
Which of the following will delete the key-value pair for the key "tiger" in the dictionary?
dic = {"lion":"wild", "tiger":"wild", "cat":"domestic", "dog":"domestic"} The correct answer is (A) del dic["tiger"].
Explanation:
del dic["tiger"]is the correct way to delete the key-value pair for"tiger"from the dictionary.- It removes the key
"tiger"and its associated value from the dictionarydic.
Other options are incorrect:
- (B) dic["tiger"].delete(): There's no
delete()method for dictionary values. - (C) delete(dic["tiger"]): There's no
delete()function in Python for dictionaries. - (D) del(dic["tiger"]): This works but is less common. The more common form is
del dic["tiger"].
So, (A) is the correct choice!
Correct Answer: A) del dic["tiger"]
2+2**3/2 के मूल्यांकन का परिणाम क्या है?
What is the result of evaluating 2 + 2 ** 3 / 2?
The correct answer is (B) 6.
Here’s the simple explanation:
The expression is:2 + 2 ** 3 / 2
-
Exponentiation first:
2 ** 3is8. -
Then division:
8 / 2is4.0. -
Finally addition:
2 + 4.0is6.0.
So the result is 6.
Correct Answer: B) 6
निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following ?
print(sum(1,2,3))
The output is (A) Error because the sum() function expects an iterable (like a list or tuple) as its first argument. You passed separate numbers instead of an iterable.
Correct usage:
print(sum([1, 2, 3])) # This would return 6
Correct Answer: A) Error
निम्नलिखित कोड का परिणाम क्या है ?
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) The output will be:
(B) {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
Explanation:
- The
update()method adds key-value pairs from dictionarybinto dictionarya. - After calling
a.update(b), the dictionaryawill now include the key-value pairs fromb. So, the updated dictionaryawill be{1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}.
Correct Answer: B) {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
निम्नलिखित पायथन अभिव्यक्ति का मूल्य क्या होगा?
What will be the value of the following Python expression?
4+2**5//10
The expression 4 + 2**5 // 10 follows the order of operations:
- 2 raised to the power of 5 gives 32 (
2**5 = 32). - Integer division of 32 by 10 results in 3 (
32 // 10 = 3). - Finally, add 4 to 3:
4 + 3 = 7.
Thus, the output is 7.
Correct Answer: B) 7
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
i = 2
while True:
if i%3 == 0:
break
print(i,end=" " )
i += 2
The given code prints values of i starting from 2 and increases i by 2 on each iteration. It prints i until i is divisible by 3. Here's the breakdown:
i = 2:2 % 3 != 0, prints 2, thenibecomes 4.i = 4:4 % 3 != 0, prints 4, thenibecomes 6.i = 6:6 % 3 == 0, the loop breaks.
Output: 2 4
So, the answer is (B) 2 4.
Correct Answer: B) 2 4
अभिव्यक्ति का मूल्यांकन करें (9//4*3-6*3//4)
Evaluate the expression (9//4*3-6*3//4)
Let's break down the expression step by step:
Expression: (9//43 - 63//4)
- 9 // 4 = 2 (Floor division of 9 by 4 gives 2)
- 2 * 3 = 6
- 6 * 3 = 18
- 18 // 4 = 4 (Floor division of 18 by 4 gives 4)
- Now, subtract: 6 - 4 = 2
So, the result of the expression is 2.
Answer: (D) 2
Correct Answer: D) 2
निम्नलिखित कथन में 'f' क्या है?
What is ‘f’ in the following statement ?
f=open(“Data.txt”, “r”)
In the statement f = open("Data.txt", "r"):
fis the file handle. It acts as a reference to the file object, allowing you to perform actions like reading from or writing to the file.
So, the correct answer is:
(B) File Handle (file object/file pointer).
Correct Answer: B) File Handle (file object/file pointer)
निम्नलिखित का आउटपुट क्या होगा?
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 it down:
- You have an array
a = np.array([1, 5, 4, 7, 8]). - Then, you add 1 to each element of the array:
a = a + 1. This results ina = [2, 6, 5, 8, 9]. - The code then prints
a[1], which is the element at index 1 in the array. After the addition,a[1]is 6.
So, the correct answer is:
(C) 6.
Correct Answer: C) 6
इस बाइनरी नंबर का मूल्य क्या है? 101001
what is value of this binary no. 101001
To convert the binary number 101001 to its decimal equivalent:
-
The binary number 101001 can be broken down as:
1×25+0×24+1×23+0×22+0×21+1×201 \times 2^5 + 0 \times 2^4 + 1 \times 2^3 + 0 \times 2^2 + 0 \times 2^1 + 1 \times 2^0 -
This simplifies to:
1×32+0×16+1×8+0×4+0×2+1×1=32+8+1=411 \times 32 + 0 \times 16 + 1 \times 8 + 0 \times 4 + 0 \times 2 + 1 \times 1 = 32 + 8 + 1 = 41
So, the decimal value of the binary number 101001 is 41.
The correct answer is:
(B) 41.
Correct Answer: B) 41
आउटपुट: SMTWTFS [-3:-1]
Output: SMTWTFS [-3:-1]
The given string is "SMTWTFS". The slice operation [-3:-1] means:
- The index -3 refers to the 3rd element from the end, which is "T".
- The index -1 refers to the last element, which is "S", but since the slice goes up to (but does not include) the last index, it will stop at "F" (the second-to-last element).
So, the result of "SMTWTFS"[-3:-1] is "TF".
Thus, the correct answer is:
(D) TF.
Correct Answer: D) TF
निम्नलिखित का आउटपुट क्या है?
What is the output of the following ?
x=123
for i in x:
print(i)
The code you've provided is:
x = 123
for i in x:
print(i)
The error occurs because x is an integer, and integers are not iterable in Python. Python allows iteration over sequences like lists, strings, and tuples, but not directly over integers.
Thus, trying to loop over an integer like this will raise a TypeError.
Correct answer: (C) Error.
Correct Answer: C) Error
>>> फ्लोट('12.6') का आउटपुट क्या है
What is the output of >>> float('12.6')
The float() function is used to convert a string or number into a floating-point number.
For the expression float('12.6'), the string '12.6' will be converted into the float 12.6.
Correct answer: (A) 12.6.
Correct Answer: A) 12.6
नीचे दिए गए कोड स्निपेट में var का डेटाटाइप क्या होगा?
What will be the datatype of the var in the below code snippet?
var = 10
print(type(var))
var = "Hello"
print(type(var))
In the given code snippet:
var = 10: Initially,varis assigned the value10, which is an integer, so its type isint.var = "Hello": Then,varis assigned the value"Hello", which is a string, so its type becomesstr.
Thus, the data type of var changes from int to str as the value is reassigned.
Correct answer: (D) int and str.
Correct Answer: D) int and str
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
from math import factorial
print(math.factorial(5))
In the code, you imported the factorial function directly, but then tried to use it with math.factorial(5). Since you didn't import math fully, you can't use math.factorial().
The correct code would be:
from math import factorial
print(factorial(5))
So, the error happens because of the incorrect use of math.factorial.
Answer: (D) Error, the statement should be: print(factorial(5)).
Correct Answer: D) Error, the statement should be : print(factorial(5))
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code?
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(2, 3) compares the values 2 and 3:
- Since 2 is less than 3, it will return
y(which is 3).
Thus, the output is 3.
Answer: (B) 3.
Correct Answer: B) 3
निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code?
if (9 < 0) and (0 < -9):
print("hello")
elif (9 > 0) or False:
print("good")
else:
print("bad")
Sure! Let's break it down:
-
First condition:
(9 < 0) and (0 < -9)9 < 0is False.0 < -9is also False.- So, the entire condition is False.
-
Second condition:
(9 > 0) or False9 > 0is True.Falseis False.- But since it's an
orcondition, if either part is true, the result is True.
-
Since the second condition is True, the output will be
"good", and it skips theelsepart.
Answer: (C) good.
Correct Answer: C) good
निम्नलिखित पायथन फ़ंक्शन का आउटपुट क्या होगा?
What will be the output of the following Python function?
complex(1+2j)
The function complex() in Python is used to create a complex number.
- The argument passed to
complex()is expected to be in the form of two parts: a real part and an imaginary part. - In the given code,
complex(1+2j)is actually passing a complex number1+2jas an argument to thecomplex()function.
When you call complex(1+2j), it will return the same complex number, i.e., 1+2j, as the argument is already a valid complex number.
Answer: (D) 1+2j.
Correct Answer: D) 1+2j
निम्नलिखित पायथन फ़ंक्शन का आउटपुट क्या होगा?
What will be the output of the following Python code?
sys.stdout.write(' Hello\n')
sys.stdout.write('Python\n')
The code uses sys.stdout.write() to print text:
sys.stdout.write(' Hello\n')prints " Hello" and moves to the next line because of the\n.sys.stdout.write('Python\n')then prints "Python" and moves to the next line.
Thus, the output is:
Hello
Python
Correct answer: (D) Hello Python
Correct Answer: D) Hello Python
आउटपुट क्या होगा:
What will be the output:
print(7//2)
print(7/2)
Let's break down the two print statements:
-
7//2: This uses floor division (//), which divides and then rounds down to the nearest integer.
So,7//2results in3. -
7/2: This uses regular division (/), which gives a float result.
So,7/2results in3.5.
Correct answer: (A) 3 and 3.5
Correct Answer: A) 3 and 3.5
आउटपुट निर्धारित करें:
Determine the output:
for i in range(20, 30, 10) :
j=i/2
print(j)
The range(20, 30, 10) produces values 20 (and stops before 30). In the loop:
- When
i = 20,j = 20 / 2 = 10.0. - The output is
10.0.
So, the answer is (C) 10.0.
Correct Answer: C) 10.0