Question

a) 7% Define a function (the function definition only) named combine_lists that receives two lists of...

a) 7% Define a function (the function definition only) named combine_lists that receives two lists of integers (the function has 2 parameters). You can assume that each list is the same length and each list is not empty. The function will create a new list which is composed of the addition of each element of the two lists. The function returns the new list.

For example, if the function is sent this list:

[2,4,6,8,10]

and this list:

[5,6,7,8,9]

then the function will return this list:

[7,10,13,16,19]



b) 2% Write the docstring for the function



c) 1% Write a single line of code (one statement) to call the function using the two example lists shown in part a)

0 1
Add a comment Improve this question Transcribed image text
Answer #1

Source Code:

def combined_list(list1,list2):
''' This combined_list function takes two lists of integers of same size as an arguments
it gives output as additon of each element of two lists
  
Parameters:
argument-1: list1 contains list of integers
argument-2: list2 contains list of integers
  
Returns:
list3 which contains additon of each element of two lists

'''
list3=[]
for i in range(0,len(list1),1):
list3.append(list1[i]+list2[i])
return list3


#calling combined_list
print(combined_list([2,4,6,8,10],[5,6,7,8,9]))

Code screenshot:

Output:

[0,10,13,16,19]

Add a comment
Know the answer?
Add Answer to:
a) 7% Define a function (the function definition only) named combine_lists that receives two lists of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with...

    Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it  listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 language:Python

  • Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with...

    Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it  listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 Language Python

  • c++ programming please. thx. Define a function template named "merge" to merge two lists of items...

    c++ programming please. thx. Define a function template named "merge" to merge two lists of items into one list including all the items of the first list followed by the items of the second list. Even though, the data type of the items of the lists is a generic type, both input lists include items of the same type. To merge the two lists, the function first dynamically allocates enough memory to accommodate the items of both lists. The allocated...

  • D.1 [3] Define a function called funD1...) that receives a string and returns a new string...

    D.1 [3] Define a function called funD1...) that receives a string and returns a new string with all the characters in the original string in an EVEN position. As an example, the following code fragment: print (funD1('abcde')) should produce the output: ace D.2 [6] Define a function funD2(...) which receives a list ist that contains single letters, single digits and single special characters and the list contains at least one element of each type). The function returns a string that...

  • Define a function add_nums_x_pos_given_list_nums (..) which receives a list that is guaranteed to only have numbers...

    Define a function add_nums_x_pos_given_list_nums (..) which receives a list that is guaranteed to only have numbers (or the empty list) and returns the sum of each number multiplied by the position where the number is. (In the case of the empty list the function it will return 0) For example add_nums_x_pos_given_list_nums ([10,20,30]) will return the value 80 which is the result of adding: 0 * 10 (10 is in position 0 in the list) + 1 * 20 + 2...

  • Define a function named double_add_digits_in_string(...) which receives a string as a parameter and returns the sum...

    Define a function named double_add_digits_in_string(...) which receives a string as a parameter and returns the sum of the digits multiplied by two. A solution using a loop is expected. As an example, the following code fragment: total = double_add_digits_in_string("xx1xx2xx3xx") print (total) should produce the output: 12

  • Write the definition of a function named timeOnHighway that receives three parameters, all of type double: mileEndingPo...

    Write the definition of a function named timeOnHighway that receives three parameters, all of type double: mileEndingPoint , mileStartingPoint , and speed . The first two parameters indicate the mile markers on an interstate at which a vehicle goes to and starts at; the third parameter indicates the speed of the vehicle in miles per hour. The function returns the number of hours it takes a vehicle to go from the starting mile marker to the ending one. The function...

  • Function Name: zip_d Parameters: two equal-sized lists Returns: a dictionary Description: Write a function, zip_d, that...

    Function Name: zip_d Parameters: two equal-sized lists Returns: a dictionary Description: Write a function, zip_d, that takes a two equal-sized lists as parameters, and zips each list into a dictionary. Sample Inputs/Outputs: Example Call: zip_d([1,2,3], ['a','b','c']) Expected Return: {1: 'a', 2: 'b', 3: 'c'} Example Call: zip_d([‘a’,’b’,’c’],[9.8,7.6,5.4]) Expected Return: {‘a’:9.8, ’b’:7.6, ’c’:5.4} please answer in python

  • kind of haskell function , In ML, define a function listsquare that when applied to the...

    kind of haskell function , In ML, define a function listsquare that when applied to the empty list of integers returns the empty list, and when applied to a non-empty list of integers return a list where each element is squared. For example, listsquares [2, 3, 4] returns [4, 9, 16]. Deine the function using a let expression in ML. val testList = [1, 2, 3, 4, 5] val testResults = listsquare testList

  • This program should use a main function and two other functions named playlist and savelist as...

    This program should use a main function and two other functions named playlist and savelist as follows: The main function: The main function should create an empty list named nums and then use a loop to add ten integers to nums, each integer in the range from 10-90. NOTE: In Python, a list is a data type. See Chapter 7. The main function should then call the playlist function and savelist function, in that order. Both of these functions take...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT