logo CodeStepByStep logo

sum3_of_2020

Write a function named sum3_of_2020 (similar to the previous exercise sum_of_2020) that accepts a string representing a file name as a parameter, reads the given file, finds the three numbers in that file that sum to exactly 2020, and returns the product of those three numbers. The file will contain exactly one non-negative integer per line. For example, if the file named numbers.txt contains the following values:

1721
979
366
299
675
1456

The three entries that sum to 2020 are 979, 366, and 675. Multiplying them together produces the answer 241861950, so the call of sum3_of_2020("numbers.txt") should return 241861950.

You may assume that the file exists and is readable, that it follows the format described above, and that there will be exactly one trio of values in the file that sum to 2020.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.