Imports#

Exercise 1: Import a new module#

The time module is part of the python standard library and can be used for many examples, for instance:

  • get the current time, using the function time() in the module, or

  • make your programm do nothing until a specific amount of time, in seconds, has passed, using the sleep(seconds) function in the module.

Import the module and use it to 1) get the time and 2) make your computer “sleep” for 4 seconds.

# your solution here

Exercise 2: Importing your own code#

The function below computes the cumulative sum over the values in a list.

Given a list [1,2,3], the cumulative sum is a new list with these items: [1, 1+2, 1+2+3] = [1, 3, 6].

values = [1,2,3,4,3,2,4]

cumulative_sum = []
for idx in range(len(values)):
    cumulative_sum.append(sum(values[:idx+1]))

print(cumulative_sum)
[1, 3, 6, 10, 13, 15, 19]

Save the function to compute the cumulative sum to a new file, import the function from the file, and use it for this new list:

new_list = [21, 45, 32, 10]
# your solution here