What is the type of the parameter for a mouseclick handler?
Refer to the CodeSkulptor documentation .
There is no parameter. \
Which of the following expressions mutate, i.e., change, list
my_list? If you’ve forgotten what the
operations do, you can look in the CodeSkulptor
my_list + [10, 20]
We want to remove the element at the front of a list. For example, we
want the following code to print
["pear", "blueberry"], respectively. What
function or method call should replace the question marks?
fruits = ["apple", "pear", "blueberry"] fruit = # ??? print fruit, fruits
Which of the following uses of
generate the list
[2, 5, 8, 11, 14]?
First, think about what each of these returns, but also try each in CodeSkulptor .
range(14, 1, -3)
range(2, 17, 3)
range(2, 14, 3) \
range(2, 17, 3) \
To correctly compute the product of a list
numbers of numbers, what statement should
replace the question marks?
numbers = # … # ??? for n in numbers: product *= n
product = numbers
product = numbers
product = 1
product = 0
product =  \
product = 1 \
We can loop over strings, too!
The following incomplete function is a simple, but inefficient, way to reverse a string. What line of code needs to replace the questions marks for the code to work correctly?
def reverse_string(s): """Returns the reversal of the given string.""" # ??? for char in s: result = char + result return result print reverse_string("hello")
result = ""
result = " "
result = 
result = 0 \
result = "" \
Imagine a game on a map. At the beginning, we might want to randomly assign each player a starting point. Which of the following expressions may we use in place of the question marks to correctly implement this functionality?
import random def random_point(): """Returns a random point on a 100x100 grid.""" return (random.randrange(100), random.randrange(100)) def starting_points(players): """Returns a list of random points, one for each player.""" points =  for player in players: point = random_point() # ??? return points
points + point
points += point \
Note that even it may look intuitive,
points += point won’t work, because operators operate typically with objects of the same type. In our case
points is a list so if we add another list (or tuple), then
points will add this list to itself - in other words extend itself.
The following function is supposed to check whether the given list of
numbers is in ascending order. For example, we want
is_ascending([2, 6, 9, 12, 400]) to return
is_ascending([4, 8, 2, 13]) should return
def is_ascending(numbers): """Returns whether the given list of numbers is in ascending order.""" for i in range(len(numbers)): if numbers[i+1] < numbers[i]: return False return True
However, the function doesn’t quite work. Try it on the suggested tests to verify this for yourself. The easiest fix is to make a small change to the highlighted code. What should it be replaced with?
range(len(numbers) - 1)
range(len(numbers - 1))
range(len(numbers)) - 1 \
range(len(numbers) - 1) \
Turn the following English description into code:
Create a list with two numbers, 0 and 1, respectively.
For 40 times, add to the end of the list the sum of the last two numbers.
What is the last number in the list?
To test your code, if you repeat 10 times, rather than 40, your answer should be 89.
Enter answer here:\
x = [0, 1] for _ in range(10): x.append(x[-1] + x[-2]) print(x[-1]) x = [0, 1] for _ in range(40): x.append(x[-1] + x[-2]) print(x[-1])