Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a) Defines a function that meets the following specifications: def LookingForSum(thisarray, sumval): thisarray: an array (list) of integers sumval: an integer The function returns: an

image text in transcribed

a) Defines a function that meets the following specifications: def LookingForSum(thisarray, sumval): thisarray: an array (list) of integers 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(12,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", vall) 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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions