Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1def find_student(names, target): return target in names | APrinting the result of .sort() shows None because .sort() changes the list and returns nothing. Print names, or use sorted(names). | |
| 2sorted(scores, reverse=True) | BWraps a search algorithm in a function so you can reuse it on any list of names and any target. | |
| 3The task asks 'Is this username already taken?' so the input is a list and a value, and the output is yes or no. Choose a search. | Cif username in all_users: | |
| 4The task asks for a leaderboard from highest to lowest, so the input is an unordered list and the output is an ordered list. Choose a sort. | Dleaderboard = sorted(points, reverse=True) | |
| 5top_score = sort(scores) | EUsing a sort when the task needs one value found and not an ordered list. Also, sort() is not a built-in function; sorted() or max() should be used. | |
| 6names.sort() print(names.sort()) | FApplies a sort algorithm to a list of scores to give a new list in order from highest to lowest. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
algorithm — A step-by-step method for solving a problem, like search or sort. Choose one by matching its input and output to your data, then wrap it in a function to reuse it.scores = [72, 95, 58, 83]
ranked = sorted(scores)
print(ranked)names = ["Ava", "Ben", "Cal"]
found = "Ben" in names
print(found)def rank(scores):
return sorted(scores)
print(rank([4, 2, 9]))data = [21, 3, 15, 8]
data.sort()
print(data)linear = 1000
binary = 10
print(linear > binary)