The Joy of Computing Using Python PART 3
The Joy of Computing Using Python PART 3
Question 17:
What does the 'else' statement represent in a conditional structure in Python?
A) It is executed if the 'if' condition is true
B) It is executed if none of the preceding 'if' or 'elif' conditions are true
AM
C) It is executed regardless of the conditions
D) It is executed before the 'if' condition
Question 18:
AY
SW
What does the 'random.randint(a, b)' function in Python do?
A) Generates a random float between a and b
B) Generates a random integer between a and b inclusive
C) Generates a random integer between a and b exclusive
D) Generates a random string between a and b characters long
Y
Question 19:
@
Page 1 MY SWAYAM
The Joy Of Computing Using Python IIT Ropar
Question 20:
What is the purpose of the 'enumerate()' function in Python?
A) To count the number of elements in a list
B) To return the index and value of elements in an iterable
C) To sort elements in a list
D) To remove elements from a list
AM
Question 21:
What is the correct way to declare a global variable in Python?
A) `global var_name = value`
B) `global var_name`
C) `var_name = global` AY
D) `var_name = value (global)`
SW
Accepted Answer: B) `global var_name`
Question 22:
What is the output of `print("Python"[::-1])` in Python?
Y
A) "nohtyP"
B) "Python"
M
C) "P"
D) Error
@
Page 2 MY SWAYAM
The Joy Of Computing Using Python IIT Ropar
Question 23:
What is the purpose of the 'pass' statement in Python?
A) It terminates the program
B) It does nothing and acts as a placeholder
C) It raises an exception
D) It prints a message to the console
AM
Question 24:
What is the correct way to create an empty set in Python?
A) `empty_set = set()`
B) `empty_set = {}`
C) `empty_set = set([])`
D) `empty_set = new set()`
AY
SW
Accepted Answer: A) `empty_set = set()`
Question 25:
What does the 'strip()' method do for strings in Python?
Y
Page 3 MY SWAYAM
The Joy Of Computing Using Python IIT Ropar
Question 26:
What is the output of `print(type(5.0))` in Python?
A) int
B) float
C) str
D) Error
AM
Question 27:
What does the 'pop()' method do for lists in Python?
A) Removes the last element from the list
AY
B) Removes the first element from the list
C) Removes the element at the specified index from the list
D) Adds a new element to the list
SW
Accepted Answer: C) Removes the element at the specified index from the list
Question 28:
What is the purpose of the 'sum()' function in Python?
Y
Page 4 MY SWAYAM
The Joy Of Computing Using Python IIT Ropar
Question 29:
What does the 'max()' function do in Python?
A) Returns the smallest element in a list
B) Returns the largest element in an iterable
C) Returns the average of elements in a list
D) Returns the total number of elements in a list
AM
Question 30:
What is the purpose of the 'chr()' function in Python?
A) Converts an integer to a string
AY
B) Converts a string to an integer
C) Converts an integer to a character
D) Converts a character to an integer
SW
Accepted Answer: C) Converts an integer to a character
Question 31:
Which of the following is a correct way to define a lambda function in Python?
Y
Page 5 MY SWAYAM
The Joy Of Computing Using Python IIT Ropar
Question 32:
What is the output of `print(3* "Hello" + " World")` in Python?
A) "HelloHelloHello World"
B) "Hello Hello Hello World"
C) "HelloHelloHelloHello World"
D) Error
AM
AY Subscribe for
PART 4
SW
MY SWAYAM
HAPPY LEARNING
THANK YOU.
Page 6 MY SWAYAM