Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sum of numbers in a file

Let’s implement something slightly useful.

In this exercise we have a file called numbers.txt that has numbers in it. Each line is a number.

Our aim is to add the numbers and print the result.

3
7
23
0
-17
98
12

Expected result is 126.

Tools

Some of the tools you might need to solve this exercise.

Solutions