If compound takes three parameters, why does only one of them change how long it runs, and why does sum_of grow exactly the same way?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Which parameter costs time can be read off a function's body before anything is measured. For each of the three given functions, find the one parameter that decides how many times its loop runs: for grow one of 'start', 'factor', 'n_steps'; for fill one of 'size', 'rounds', 'value'; for wages one of 'weeks', 'rate', 'hours'. Fill in the dictionary costly, which maps each function's name to that parameter name.
def grow(start, factor, n_steps):
for i in range(n_steps):
start = start * factor
return start
def fill(size, rounds, value):
total = 0
for r in range(rounds):
total = total + size * value
return total
def wages(weeks, rate, hours):
pay = 0
for w in range(weeks):
pay = pay + rate * hours
return pay