I am new to programming in python and need help doing this.
I have a text file with several numbers like this:
12 35 21
123 12 15
12 18 89
I need to be able to read the individual numbers of each line to be able to use them in mathematical formulas.
In python, you read a line from a file as a string. You can then work with the string to get the data you need:
I’ve done it all in a bunch of steps, but you’ll often see people combine them:
Finally, using them in a mathematical formula is easy too. First, create a function:
Now iterate through your file calling the function: