The Joy Of Computing Using Python IIT Ropar
The Joy of Computing Using Python
IMP QUESTIONS 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
Accepted Answer: B) It is executed if none of the preceding 'if' or 'elif'
conditions are true
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
Accepted Answer: B) Generates a random integer between a and b inclusive
M
Question 19:
@
Which of the following data types is not supported in Python?
A) List
B) Tuple
C) Set
D) Array
Accepted Answer: D) Array
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
Accepted Answer: B) To return the index and value of elements in an iterable
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
@
Accepted Answer: A) "nohtyP"
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
Accepted Answer: B) It does nothing and acts as a placeholder
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
A) Removes all characters from the beginning of the string
B) Removes all characters from the end of the string
M
C) Removes leading and trailing whitespaces from the string
D) Converts the string to uppercase
@
Accepted Answer: C) Removes leading and trailing whitespaces from the
string
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
Accepted Answer: B) float
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
A) Adds up all the elements of an iterable
B) Calculates the average of all the elements in a list
M
C) Multiplies all the elements of an iterable
D) Sorts the elements of an iterable
@
Accepted Answer: A) Adds up all the elements of an iterable
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
Accepted Answer: B) Returns the largest element in an iterable
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
A) `lambda function_name(parameters): expression`
B) `function_name = lambda(parameters): expression`
M
C) `def function_name(parameters): expression`
D) `function_name(parameters): expression`
@
Accepted Answer: A) `lambda function_name(parameters): expression`
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
Accepted Answer: A) "HelloHelloHello World"
AM
AY Subscribe for
PART 4
SW
MY SWAYAM
PDF OF ALL ABOVE MCQ’S IS AVAILABLE IN THE
Y
DESCRIPTION BOX OF THIS VIDEO.
FOR NEXT PART COMMENT BELOW AND SUBSCRIBE TO THE
M
“MY SWAYAM” CHANNEL
@
HAPPY LEARNING
THANK YOU.
Page 6 MY SWAYAM