Page 54 - PYTHON-11
P. 54
Q 20 and Q 21 are Assertion (A) and Reasoning (R) based questions. Mark the correct choice as:
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
20. Assertion (A): In Python, a tuple is immutable. [1]
Reasoning (R): Once a tuple is created, its elements cannot be changed or modified.
Ans. (a) Both A and R are true and R is the correct explanation of A.
21. Assertion (A): A variable in Python must be declared before use. [1]
Reasoning (R): Python is a dynamically typed language.
Ans. (d) A is false but R is true.
Section B (7 × 2 = 14 Marks)
22. Draw a logic circuit for the following expression: [2]
(A + B)'.C
Ans. A (A + B)'.C
B
C
23. Write a Python program to print all odd numbers from 1 to 50. [2]
Ans. for i in range(1, 51):
if i % 2 != 0:
print("Odd number:", i)
24. Write any four features of Python. [2]
Ans. The features of Python are as follows:
(a) It is free, open-source and portable language having a large repository of libraries.
(b) It is an interpreted and interactive language.
(c) It is used for both scientific and non-scientific programming.
(d) It is a dynamically typed object-oriented programming language.
25. What will be the output of the following code? [2]
import random
print(random.randrange(5, 20, 3))
Ans. 5, 8, 11, 14, 17
26. What are modules? Why do we need them? [2]
Ans. Module is a file containing Python definitions and statements. We need modules because of the following
features:
(a) A module allows code reuse.
(b) It enables clearer code organization.
27. (a) What is the purpose of else in a loop? [2]
Or
(b) What is None in Python?
Ans. (a) Looping statements can have an optional else block. else block is executed if the terms in the sequence do
not match or when the loop gets over.
Or
M.3