Control Flow and Functions Flashcards
7 cards from real PCEP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Control Flow and Functions flashcards as text
What is the output of the following code? for i in range(3): if i == 1: continue print(i)
Answer: 0 2
The `continue` statement skips the rest of the loop body when `i == 1`, so 1 is never printed.
Which of the following correctly defines a function that returns the square of a number?
Answer: def square(n): return n * n
Python functions are defined with `def`, require a colon, and can use `return` to send back a value.
What value does a Python function return if it has no `return` statement?
Answer: None
A function without a `return` statement implicitly returns `None`.
What is the output of the following? x = 10 if x > 5: print('A') elif x > 8: print('B') else: print('C')
Answer: A
Once the first `if` condition is True, the `elif` and `else` branches are skipped entirely.
How many times does the following loop execute? i = 0 while i < 5: i += 2
Answer: 3
i takes values 0, 2, 4 before i becomes 6 which fails the condition, so the loop runs 3 times.
What does the `pass` statement do inside a function body?
Answer: Does nothing; acts as a placeholder
`pass` is a no-op statement used as a placeholder where Python syntax requires a statement but no action is needed.
What is the result of calling `range(1, 10, 3)` as a list?
Answer: [1, 4, 7]
`range(1, 10, 3)` starts at 1, steps by 3, and stops before 10, yielding 1, 4, 7.