Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

Question Can a Keogh plan fund be reached by the owners creditors?

Answered: 1 week ago

Question

Question What happens to my plan if I die?

Answered: 1 week ago