Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding Variable
#1
Hey I have this homework problem set that I feel like should be very simple but I am stuck:

Write a function add(vals1, vals2) that takes as inputs two lists of 0 or more numbers, vals1 and vals2, and that uses recursion to construct and return a new list in which each element is the sum of the corresponding elements of vals1 and vals2. You may assume that the two lists have the same length.

For example:

>>> add([1, 2, 3], [3, 5, 8])
[4, 7, 11]
Note that:

The first element of the result is the sum of the first elements of the original lists (1 + 3 –> 4).
The second element of the result is the sum of the second elements of the original lists (2 + 5 –> 7).
The third element of the result is the sum of the third elements of the original lists (3 + 8 –> 11).


This is what I have:
def add(vals1, vals2):
   return (vals1 + vals2)
Reply


Messages In This Thread
Adding Variable - by kevinwoo00 - Feb-18-2019, 03:51 AM
RE: Adding Variable - by Lonewolf - Feb-18-2019, 08:16 AM
RE: Adding Variable - by perfringo - Feb-18-2019, 04:51 PM
RE: Adding Variable - by ichabod801 - Feb-18-2019, 04:17 PM
RE: Adding Variable - by ichabod801 - Feb-18-2019, 04:18 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020