The question is as follows; "Write a Python program to read a file with lake and fish data and set report the lake identification number, the lake name, and the fish weight in a tabular format (use string zones with formatting). The program should calculate the average fish weight reported."
Lake identification;
1000 Chemo
1100 Greene
1200 Toddy
The file I must read "FishWeights.txt" contains the following data;
1000 4.0
1100 2.0
1200 1.5
1000 2.0
1000 2.2
1100 1.9
1200 2.8
My code;
f = open("fishweights.txt")
print(f.read(4), "Chemo", f.readline(4))
print(f.read(5), "Greene", f.read(5))
print(f.read(4), "Toddy", f.read(5))
print(f.read(5), "Chemo", f.read(4))
print(f.read(5), "Chemo", f.read(4))
print(f.read(5), "Greene", f.read(4))
print(f.read(5), "Toddy", f.read(4))
The output I receive is;
1000 Chemo 4.0
1100 Greene 2.0
1200 Toddy 1.5
1000 Chemo 2.0
1000 Chemo 2.2
1100 Greene 1.9
1200 Toddy 2.8
This is correct to the extent that I must have the Lake's ID number, Name, and fish weight per lake displayed. But I need to be able to have a calculation where it averages all the fishes weights at the end. The output SHOULD be formatted neatly and look as follows;
1000 Chemo 4.0
1100 Greene 2.0
1200 Toddy 1.5
1000 Chemo 2.0
1000 Chemo 2.2
1100 Greene 1.9
1200 Toddy 2.8
The average fish weight is: 2.34
Any help is appreciated, Just a beginning coder here seeking help to have a full understanding of the subject. Thank you!
printing the data as you read it in, you will need to store the values in variable(s) and act on them to do the math as you read them inLake Idinfo ? Is that in another text file or you are free to format it as you please?