My teacher told my class to do this homework:
Given a list of values pi ∈ R3 = {xi, yi, zi} in the file m.txt, write a program that calculates m = {mx, my, mz} = Σi pi / N ∈ R3, where N is the number of values read. The file is in CSV format, a value of pi per line, with values separated by commas".
Now my file is like this:
12.5, 45.1, 23.1
4.2, 2.0, 6.5
12.7, 48.5, 34.0
and i tried doing something like this:
f = open("m.txt", "r")
sx = 0.0
sy = 0.0
sz = 0.0
for i in f:
p = i.split(",")
px = p[0]
py = p[1]
pz = p[2]
sx = sx + float(px)
mx = sx / len(px)
sy = sy + float(py)
my = sy / len(py)
sz = sz + float(pz)
mz = sz / len(pz)
print [mx,my,mz]
but when i run the program, it considers not the lenght of the string, but the lenght of the value of the string. Can you help me doing this homework without using any arrays? Thanks in advance!