#1
What does a 'for' loop do in programming?
It repeats a block of code while a condition is true
It performs a specified action multiple times
It executes a block of code only if a condition is true
It defines a function
#2
What is the output of the following Python code?
for i in range(5):
print(i)
0 1 2 3 4
1 2 3 4 5
1 2 3 4
0 1 2 3
#3
What is the purpose of an 'if-else' statement in programming?
To define a loop
To execute a block of code repeatedly
To perform different actions based on different conditions
To skip the current iteration of the loop and proceed to the next one
#4
What is the difference between '==' and '!=' in programming?
'==' checks for equality, while '!=' checks for inequality
'==' checks for inequality, while '!=' checks for equality
'==' is used to assign a value, while '!=' is used to compare values
'==' and '!=' are interchangeable
#5
What is the output of the following Python code?
x = 5
while x > 0:
print(x)
x -= 1
5 4 3 2 1
1 2 3 4 5
0 1 2 3 4
5 4 3 2 1 0
#6
What is the purpose of the 'else' statement in a loop?
To execute a block of code only if a condition is true
To define a loop
To execute a block of code when the loop condition is false
To skip the current iteration of the loop and proceed to the next one
#7
In programming, what is a 'conditional statement'?
A statement that performs a specific action based on a condition
A statement that executes a block of code repeatedly
A statement that defines a function
A statement that initializes a variable
#8
What is the purpose of a 'break' statement in a loop?
To skip the current iteration of the loop and proceed to the next one
To exit the loop completely
To restart the loop from the beginning
To execute a specific block of code when a condition is met
#9
What does the 'continue' statement do in a loop?
It terminates the loop
It skips the remaining code in the loop and proceeds to the next iteration
It restarts the loop from the beginning
It executes a specific block of code when a condition is met
#10
In Python, what does the 'range()' function do?
It generates a list of numbers
It creates a range object representing a sequence of numbers
It generates a sequence of numbers
It initializes a variable with a specific value
#11
What is the purpose of a 'nested loop' in programming?
To create a loop that runs infinitely
To create a loop inside another loop
To create a loop that only runs once
To terminate a loop
#12
Which of the following is true about the 'elif' statement in Python?
It is short for 'else if' and is used to check multiple conditions
It is used to define a loop
It is used to execute a block of code repeatedly
It is used to skip the current iteration of the loop and proceed to the next one
#13
What is the difference between 'while' and 'for' loops in programming?
There is no difference, they can be used interchangeably
A 'while' loop iterates until a condition is true, whereas a 'for' loop iterates over a sequence of elements
A 'while' loop iterates over a sequence of elements, whereas a 'for' loop iterates until a condition is true
A 'while' loop executes a block of code only if a condition is true, whereas a 'for' loop performs a specified action multiple times
#14
What does the 'pass' statement do in Python?
It terminates the loop
It skips the remaining code in the loop and proceeds to the next iteration
It is a null operation, meaning nothing happens when it executes
It executes a specific block of code when a condition is met
#15
What is an infinite loop in programming?
A loop that runs a specified number of times
A loop that runs until a condition is false
A loop that never terminates
A loop that runs only once
#16
What is the purpose of a 'generator' in Python?
To generate a list of numbers
To create a range object representing a sequence of numbers
To generate a sequence of values lazily
To execute a specific block of code when a condition is met
#17
What does the 'reduce()' function do in Python?
It applies a function to each item in an iterable and returns a list of the results
It reduces a list to a single value by applying a function cumulatively
It sorts an iterable in ascending order
It reverses an iterable