Ask Question
9 November, 03:45

g Write a Racket function (process lst1 lst2) that processes the corresponding elements of the two lists and returns a list. If the corresponding elements are both numbers, include the sum of the two corresponding elements in the list that is returned.

+2
Answers (1)
  1. 9 November, 04:46
    0
    def process (lst1, lst2) : newList = [] for i in range (0, len (lst1)) : sum = lst1[i] + lst2[i] newList. append (sum) return newList list1 = [1, 3, 5, 7, 9] list2 = [2, 4, 6, 8, 10] print (process (list1, list2))

    Explanation:

    Firstly, create a function process that takes two input lists (Line 1). In the function, create a new list (Line 2). Use a for loop to traverse through the elements of the two lists and total up the corresponding elements and add the sum to the new list (Line 3 - 5). At last, return the new list (Line 6).

    In the main program, create two sample list and use them as arguments to test the function process (Line 8 - 9). We shall get the output [3, 7, 11, 15, 19].
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “g Write a Racket function (process lst1 lst2) that processes the corresponding elements of the two lists and returns a list. If the ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers