Last Updated: January 3, 2026
31 quizzes
Complete the expression to check if access_level is not equal to 0 before printing a message
print(access_level 0)Click an option to fill the blank:
Complete the expression to iterate over numbers 0 through 4 when building a list of squares
squares = [n * n for n in (5)]Click an option to fill the blank:
Complete the expression to choose 'adult' when age is 18 or more, otherwise 'minor'
status = 'adult' if age >= 18 'minor'Click an option to fill the blank:
You want to run a block of code only when a condition is false. Which structure is most suitable?
Which statement best describes an elif clause?
When is a ternary (conditional) expression most appropriate?
What does this loop do? for name in users: print(name)
Which while loop condition is most likely to create an infinite loop if count is not changed inside the loop?
In a for loop, what does the continue statement do?
When will the else block of a for loop execute?
What is a common use case for nested loops?
In match-case, what does the underscore (_) pattern represent?
You want to validate input until it is correct. Which loop is typically more appropriate?
What happens when break is executed inside a while loop that has an else clause?
Order the steps to use a while loop that counts down from 3 and then prints 'Go!'.
Drag and drop to reorder, or use the arrows.
Order the steps to use match-case to handle different HTTP status codes.
Drag and drop to reorder, or use the arrows.
What is the output of this code? status = 'member' message = 'Welcome' if status == 'member' else 'Please sign up' print(message)
1status = 'member'
2message = 'Welcome' if status == 'member' else 'Please sign up'
3print(message)What is the output of this code? level = 5 if level > 10: result = 'high' else: result = 'low' print(result)
1level = 5
2if level > 10:
3 result = 'high'
4else:
5 result = 'low'
6print(result)What is the output of this code? items = [1, 3, 5] for number in items: if number % 2 == 0: print('even') break else: print('no even numbers')
1items = [1, 3, 5]
2for number in items:
3 if number % 2 == 0:
4 print('even')
5 break
6else:
7 print('no even numbers')What is the output of this code? matrix = [[1, 2], [3, 4]] product = 1 for row in matrix: for value in row: product *= value print(product)
1matrix = [[1, 2], [3, 4]]
2product = 1
3for row in matrix:
4 for value in row:
5 product *= value
6print(product)What is the output of this code? value = 'hello' match value: case 'hi': msg = 'short greeting' case 'hello': msg = 'longer greeting' case _: msg = 'unknown' print(msg)
1value = 'hello'
2match value:
3 case 'hi':
4 msg = 'short greeting'
5 case 'hello':
6 msg = 'longer greeting'
7 case _:
8 msg = 'unknown'
9print(msg)Find the bug in this code that searches for a username using a for-else loop.
Click on the line(s) that contain the bug.
def find_user(target, users): for user in users: if user == target: return True break else: return FalseFind the bug in this code that should count down using a while loop.
Click on the line(s) that contain the bug.
def countdown(start): value = start while value >= 0: print(value) value + 1 Match each keyword with its effect on loop execution.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each control-flow construct with a typical use case.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to use a for-else loop that reports when a discount code is not found.
def has_discount(search_code, all_codes): for discount in all_codes: if discount == search_code: return else: return Click an option to fill blank 1:
Complete the code to build a multiplication table using nested loops.
def multiplication_table(limit): for row in : for column in range(1, limit + 1): print(row * column, end=' ') Click an option to fill blank 1:
Complete the code so that a while loop keeps asking until a non-empty name is provided.
def ask_name(get_input): customer_name = '' while : customer_name = get_input() return Click an option to fill blank 1:
Complete the code to choose a label with match-case based on a priority number.
def label_priority(priority): match priority: case 1: return 'high' case 2 | 3: return case _: return Click an option to fill blank 1:
Click the line that prevents this while loop from ever stopping.
Click on the line to select.
counter = 3while counter > 0: print(counter) # missing update to counter hereClick the line where the loop should skip processing negative scores.
Click on the line to select.
scores = [10, -3, 7]for score in scores: if score < 0: continue print('Valid:', score)