File I/O in Python
15 questions · 12 min · Medium
Test your knowledge of control statements in Python with 20 questions covering if, elif, else, nested conditions, for loops, while loops, break, continue, pass, and loop control.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. if
The if statement executes its indented block when its condition evaluates to True.
B. elif
The elif keyword allows Python to test another condition after a preceding if or elif condition is false.
C. else
The else block executes when none of the preceding if or elif conditions evaluates to True.
A. Yes
The condition x > 5 is true because 10 is greater than 5, so the print statement executes.
A. for
The for loop iterates over items in an iterable such as a list, tuple, string, or range.
B. while
A while loop repeatedly executes its body while its condition evaluates to True.
B. 0 1 2
range(3) produces the values 0, 1, and 2, so those values are printed.
C. break
The break statement immediately exits the nearest enclosing for or while loop.
B. continue
The continue statement skips the remaining statements in the current iteration and proceeds to the next iteration.
C. Acts as a placeholder and performs no operation
The pass statement does nothing when executed and is commonly used where Python syntax requires a statement.
B. B
The condition x > 20 is false because x is 15, so the else block executes.
A. An if statement inside another if statement
A nested conditional occurs when one conditional statement is placed inside the block of another conditional statement.
A. 0 1 2
The loop prints 0, 1, and 2. When i becomes 3, break terminates the loop before 3 is printed.
B. 0 1 3 4
When i equals 2, continue skips the print statement for that iteration, while the other values are printed.
A. range()
The range() function produces an iterable sequence of integers commonly used with for loops.
B. The loop body does not execute
A while loop checks its condition before each iteration, so a false initial condition means its body is skipped.
B. else
Python loops can have an else clause that executes when the loop finishes normally rather than through a break statement.
C. 0 1 2 Done
The loop prints 0, 1, and 2 and then completes normally, so its else block prints Done.
B. and
The and operator produces True when all of its operands are true.
C. not
The not operator reverses a Boolean value, turning True into False and False into True.