[Tutor] exercise problem
Roelof Wobben
rwobben at hotmail.com
Thu Aug 26 21:02:38 CEST 2010
Hello,
I have this exercise:
Lists can be used to represent mathematical vectors. In this exercise and several that follow you will write functions to perform standard operations on vectors. Create a file named vectors.py and write Python code to make the doctests for each function pass.
Write a function add_vectors(u, v) that takes two lists of numbers of the same length, and returns a new list containing the sums of the corresponding elements of each.
def add_vectors(u, v):
"""
>>> add_vectors([1, 0], [1, 1])
[2, 1]
>>> add_vectors([1, 2], [1, 4])
[2, 6]
>>> add_vectors([1, 2, 1], [1, 4, 3])
[2, 6, 4]
>>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
[13, -4, 13, 5]
"""
add_vectors should pass the doctests above
I think that u is the name of the new list and v is the number which represent the number which must be eveluated.
Is this right or do I mis understood the exercise ?
Roelof
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100826/183706d3/attachment.html>
More information about the Tutor
mailing list