In this task, we will develop a program to detect whether a target number is the sum of k elements in the given list num

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

In this task, we will develop a program to detect whether a target number is the sum of k elements in the given list num

Post by answerhappygod »

In This Task We Will Develop A Program To Detect Whether A Target Number Is The Sum Of K Elements In The Given List Num 1
In This Task We Will Develop A Program To Detect Whether A Target Number Is The Sum Of K Elements In The Given List Num 1 (31.32 KiB) Viewed 17 times
In This Task We Will Develop A Program To Detect Whether A Target Number Is The Sum Of K Elements In The Given List Num 2
In This Task We Will Develop A Program To Detect Whether A Target Number Is The Sum Of K Elements In The Given List Num 2 (57.52 KiB) Viewed 17 times
In this task, we will develop a program to detect whether a target number is the sum of k elements in the given list numbers (note that the elements in numbers are positive integers and we input the integers one by one, one integer at a time, and terminated by - 1). Please carefully read the below cases for a better understanding. Case 1 INPUT: 1 2 8 9 39 92 161 -1 209 3 OUTPUT: Yes Explanation: It print "Yes" because there are 3 numbers in the given list that sum up to 209 (9 + 39 + 161)
Case 2 INPUT: 32 392 93022 349895 -1 1280298482 2 OUTPUT: No Explanation: It print "No" because we cannot find 2 numbers in the given list [32, 293, 93022, 349895] to sum up to 1288298402 Given program 1. number - int(input) 2. numbers - 1 3. while number 1 = -1: 4. numbers.append(number) 5. number - int(input()) 6. target = int(input) 7. k int(input()) 8. 9. 10. def isExist(# define parameters): # your implementation 12. 13. 14. if isExist(# input the appropriate variables): 15. print("Yes") 16. else: 17. print("No") 11. 1. You are expected to use recursion algorithm to solve this problem. It will have a 20% deduction if your submission is not a recursion solution. 2. Hint: If the current number x should be included in finding the target number, then summing up k elements to find the target will be equivalent to summing up [k-1] elements to find (target -x] Similarly, try to figure out the recurrence relationship for the situation where x should not be included in the process. 3. Please read the given code carefully for better understanding. 4. You can start the recursion on is_exist(), or you can define another recursive function and use is_exist() to call it. You may define as many functions as you need but you are not required to do 5. You must show the output of the function using the print) provided above. 6. You are not allowed to change any line of code in the given program. 7. Make sure your program can handle input range 1< < 6, where k is a positive integer. For example, in the above case ([1, 2, 8, 9, 39, 92, 161), 109, 3), the kis 3. 8. You can use any built-in functions in Python. so.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply