python program to divide numbers in file in selected order [closed]

Ok, this will get you just started with the basics, but you’ll have to figure out the logic of your math, the various index values, and order of operations to solve your problem.

This simply opens a file and displays its contents. The data is read as strings, and converted to floats so that you can do math with the numbers.

I strongly recommend you read a Python tutorial, or better yet work in a programming language you are more familiar with.

with open('data.txt') as f:
    data = f.readlines()
    for i in range(len(data)):
        result = float(data[i])
        print result

Contents of data.txt


The rest is up to you. Please feel free to come back and ask for help when you get stuck with a specific problem.

Finally, since the data from the file ends up in a variable name data which is a Python list, reading through these Python docs and this tutorial should be helpful in understanding this data structure.

Leave a Comment