Checkpoint
Python, one step at a time
Twelve questions from the whole module, on inputs you have not seen. Most aim at a classic slip: a second name for one list, a tie, a return in the wrong place, a guard on the wrong side, a bug far from the line its traceback names. Work each one on paper before you answer, with a small table of names, the way you would in a round with no run button. To pass you need 80%, which is 10 of the 12.
- Question 1 of 12.
Type exactly what this prints. A list prints in square brackets, like
[1, 2].a = [2, 4, 6] b = a c = a[:] b[0] = 9 a = [1] print(a, b, c) - Question 2 of 12.
A job ran for 200 seconds. Type exactly what this prints, one line per
print.seconds = 200 print(seconds // 60, seconds % 60) print(seconds / 100, seconds // 100) - Question 3 of 12.
This is the busiest-day walk with one character changed:
>=instead of>. What does it print? Type a whole number.orders = [12, 30, 7, 30] best_day = 0 for i in range(len(orders)): if orders[i] >= orders[best_day]: best_day = i print(best_day)best_dayType a number: 12, -1, 0.5 and 3/4 all work.
- Question 4 of 12.
How many times does the body of this
whileloop run? Type a whole number.n = 4071 digits = 0 while n > 0: n = n // 10 digits += 1passesType a number: 12, -1, 0.5 and 3/4 all work.
- Question 5 of 12.
findshould return the position oftargetinnums, or -1 if it is not there. What doesfind([5, 8, 2], 8)return?def find(nums, target): for i in range(len(nums)): if nums[i] == target: return i else: return -1 - Question 6 of 12.
With
nums = [4, 9], which of these lines raise anIndexError? Choose every line that does.Choose every option that applies.
- Question 7 of 12.
Type exactly what this prints.
nums = [3, 1, 2] a = sorted(nums) b = nums nums.sort() print(a, b, nums.sort()) - Question 8 of 12.
The string below starts with two spaces, has two spaces after
ETL, one betweenrunsandnightly, and one at the end. Type exactly what this prints.line = " ETL runs nightly " print(len(line.split()), len(line.split(" "))) print("_".join(line.split())) - Question 9 of 12.
What is
counts[13]after this runs? Type a whole number.counts = [0] * 26 for c in "banana": counts[ord(c) - ord("a")] += 1counts[13]Type a number: 12, -1, 0.5 and 3/4 all work.
- Question 10 of 12.
Type exactly what this prints.
row = [0, 0] grid = [row] * 3 grid[1][0] = 7 row[1] = 4 print(grid) - Question 11 of 12.
first_wordshould return the first word in lowercase, so this program should printload. Instead it stops with the traceback below (file path shortened). Where is the bug?def clean(words): out = [] for w in words: out.append(w.lower()) def first_word(words): cleaned = clean(words) return cleaned[0] print(first_word(["Load", "Table"]))Traceback (most recent call last): File "solution.py", line 10, in <module> print(first_word(["Load", "Table"])) ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "solution.py", line 8, in first_word return cleaned[0] ~~~~~~~^^^ TypeError: 'NoneType' object is not subscriptable - Question 12 of 12.
Run the tests before you submit. This question counts as correct if your latest run passes every check.
Code itThe busiest day, by name Write
busiest(days, orders).daysholds day names andordersholds each day's order count, in the same order. Return a tuple(day, count)for the day with the most orders. On a tie, return the earliest of the tied days. If there are no days, returnNone. For example,busiest(["mon", "tue", "wed"], [12, 30, 7])is("tue", 30).Write your code where the starter saysraise NotImplementedError, then press Run tests. Each check says what it expects.