Question: Using python def LookingForSum(thisarray, sumval) thisarray: an array (list) of intege sumval: an integer The function returns: an integer specifying the first location in the

Using python
def LookingForSum(thisarray, sumval) thisarray: an array (list) of intege sumval: an integer The function returns: an integer specifying the first location in the list where the sum of a sequence of terms adds up to sumval. If there is no such location, return -1 See the following examples: LookingForSum([2, 3, 2,-1, 5, -2], 4) returns 1... because the sequence 3, 2, -1 starts at 1 and sums to 4 LookingForSum([2, 3, 2, -1, 5, -2], 1) returns 2... because the sequence 2, -1 starts at 2 and sums to 1 LookingForSum([2, 3, 2, -1, 5, -2], 6) returns 0... because the sequence 2, 3, 2, -1 starts at 0 and sums to 6 LookingForSum(12, 3, 2, -1, 5, -2], 3) returns 1... because the sequence 3 starts at 1 and sums to 3 LookingForSum([2, 3, 2,-1, 5, -2], 8) returns -1... because there is no sequence that sums to 8 Huge hint: decide the process you would use to do this with pencil, paper and calculator. Think about the loops needed (suggested by the work EVERY)!!! Then write Python to perform that process b) The program contains and calls the following main() function def main(): thatarray [3, 4, 2, -7, 5, 2, 1, -1] vall - LookingForSum(thatarray, -2) print("vall", val1) val2 = LookingForSum(thatarray, 8) print("val2", val2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
