Exam habits
A routine saves points when the clock is running:
1. Start from the given signature. Keep the function name and the parameters exactly as handed to you.
2. Run the samples first. They catch misread statements in seconds.
3. Then submit. Submissions are unlimited and the best one counts, so a failed hidden test costs you only time.
4. Return the type the statement names. A list of digits is not the string "405", and a whole number should not become 3.5.
5. No input(), no print. The tests supply the arguments and read the return value.
Which type you return can change the value itself. 7 / 2 is 3.5 but 7 // 2 is 3.
See it run
def solution(a, b): return (a + b) // 2 samples = [(3, 4), (10, 0)] for a, b in samples: print(solution(a, b))
Run the samples before you submit: each one is a call with known inputs.
Practice exam habits
Exercise 1
Write solution(a, b) returning the average of two whole numbers rounded down to a whole number (toward negative infinity). For example, solution(3, 4) is 3 and solution(-3, -4) is -4. Return a whole number, not a decimal.
Exercise 2
Write solution(n) returning the digits of the whole number n as a list of integers, left to right. n is zero or more. For example, solution(405) is [4, 0, 5] and solution(0) is [0].
Exercise 3
The starter below has the right signature but also some leftover practice code. Finish solution(seats, wanted): seats is a list of 0 (free) and 1 (taken). Return True if there are at least wanted free seats in a row, else False. wanted is at least 1. For example, solution([1, 0, 0, 1], 2) is True and solution([0, 1, 0], 2) is False. Remove input(): the tests pass their values as arguments.
The explanation and tasks are public. Running this lesson requires an account with course access.
Practice
Loading Python…Visualizer Watch your code run line by line
Run your code, then choose Play to follow its execution.