Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I am programming using the python language. I am writing a function that tak

ID: 3547053 • Letter: H

Question

Hi, I am programming using the python language. I am writing a function that takas as input a list of positve numbers and a positve number as a target. It should return True if there are three numbers in the list that add up to the given Target. For example, if the input list is [5,4,10,20,15,19] and target is 38, then True should be returned since 4 + 15+19=38.Could you give me some hints on how to take a list of any length and pick three numbers from the list that add up to a given number? I guess my question is could you give me hints as to how can I be able to pick from the list any number without looking for it adjacently-that is if the numbers that add up to the target are scattered across the list and are not adjacent?

Explanation / Answer

You can go through the list with a loop and see if any of the indexes add up to the target. So depending on the size of the list if 5 is the first element add 5 with 4 and see if that adds up to target, if not then add the next numbers in the list and see if that adds up to target and repeat again until you get the target. If the the number that are added become greater than the target than the start over with the second number in the list and repeat process.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote