# 这是一篇来自加拿大的关于解决一些函数相关问题的计算机代写

Part 1 (0 points): Warm-up

Do NOT submit this part, as it will not be graded. However, doing these exercises might help you to do the second part of the assignment, which will be graded. If you have difffficulties with the questions of Part 1, then  we suggest that you consult the TAs during their offffice hours; they can help you and work with you through  the warm-up questions. You are responsible for knowing all of the material in these questions.

Warm-up Question 1 (0 points)

Write a function split_at_space that takes as input a string of words with spaces in between each word and returns a list of the words in the string. Do not use the string method split to do this.

>>> split_at_space(‘aardvark butterfly carrot’)

[‘aardvark’, ‘butterfly’, ‘carrot’]

Warm-up Question 2 (0 points)

Write a function generate_random_list which takes an input an integer n and returns a list containing n random integers between 0 and 100 (both included). Use the random module to do this.

Warm-up Question 3 (0 points)

Write a function sum_numbers which takes as input a list of integers and returns the sum of the numbers in the list. Do not use the built-in function sum to do this.

Warm-up Question 4

(0 points)

Write a function same_elements which takes as input a two dimensional list and returns True if all the elements in each sublist are the same and False otherwise. For example,

>>> same_elements([[1, 1, 1], [‘a’, ‘a’], [6]])

True

>>> same_elements([[1, 6, 1], [6, 6]])

False

Warm-up Question 5 (0 points)

Write a function flatten_list which takes as input a two dimensional list and returns a one dimensional

list containing all the elements of the sublists. For example,

>>> flatten_list([[1, 2], [3], [‘a’, ‘b’, ‘c’]])

[1, 2, 3, ‘a’, ‘b’, ‘c’]

>>> flatten_list([[]])

[]

Part 2

The questions in this part of the assignment will be graded.

The main learning objectives for this assignment are:

• Apply what you have learned about lists and nested lists.
• Understand how to raise exceptions in cases of invalid inputs.
• Solidify your understanding of working with loops and strings.
• Apply what you have learned about file IO and string manipulation.
• Understand how to write a docstring and use doctest, in particular when working with files.
• Practice making copies of lists so that inputs are not modified.

Note that this assignment is designed for you to be practicing what you have learned in our  lectures up to and including Lecture 22 (File IO II). For this reason, you are NOT allowed to  use anything seen after that lecture or not seen in class at all. You will be heavily penalized  if you do so.

For full marks, in addition to the points listed on page 1, make sure to add the appropriate documentation string (docstring) to all the functions you write. The docstring must contain the following:

• The type contract of the function.
• A description of what the function is expected to do.
• At least three (3) examples of calls to the function. You are allowed to use at most one example per function from this PDF.

Examples

For each question, we provide several examples of how your code should behave. All examples are given as if you were to call the functions from the shell.