Summing Three Numbers from Any File¶

Create several more files in Notepad containing three integers separated by some whitespace. Save them in your folder as 3nums1.txt, 3nums2.txt, 3nums3.txt, etc.

Then write a program that asks the user which file to open. Then it should open that file, and read the three integers from the file. It should then display (on the screen) the total of the integers.

Name your program sum_from_any_file.py

Which file would you like to read numbers from: 3nums2.txt
Reading numbers from file "3nums2.txt"

6 + 3 + 3 = 12

Which file would you like to read numbers from: 3nums4.txt
Reading numbers from file "3nums4.txt"

7 + 2 + 5 = 14

©2021 Daniel Gallo

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.

Creative Commons License

Adapted for Python from Graham Mitchell’s Programming By Doing