Ask Question

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.

+4
Answers (1)
  1. 20 April, 21:10
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers