Create a text file called name-and-numbers.txt
and put a name on the first line and then three numbers (one per line) on the lines below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Getting name and three numbers from a file... done. Your name is Samantha Showalter 5 + 6 + 7 = 18
The readline()
method reads an entire line from the file and returns it as a string. It has a "\n" at the end, which the .strip()
method removes.
- Open the text file and change the name or numbers. Save it. Then run your program again.
©2017 Graham Mitchell