I apologize that this is going to be kind of long. I am very grateful for any thoughts you may have.
I'm taking a python class. This week we are learning about working with .txt files within a program.
We have been given some practice .txt files. Each file is a list of different data points for each hour on a given day. The list (when I say list, I mean the data is in a list in a .txt file, I am not talking about a list like those used in a python program) has four items of data for each hour of a given day as follows:
time
temperature in Farenheit
dewpoint in Farenheit
wind speed in mph
An example from one of the files looks like this:
12AM
18.1
15.0
4.1
1AM
18.0
15.5
4.2
We are supposed to do several things with this data. One of them is to create a report that will print out the data from the file. It should look like this:
Time Temperature Dew Point Windspeed
12AM 18.1 15 4.1
1AM 18.0 15.5 4.2
And so on.
We are supposed to accomplish this using while and/or for loops. We cannot use lists of any kind, so we cannot use the .txt file to create a list within python and then work with the list. This must be as simple as possible. We are only supposed to use the information we have learned so far in the class. Obviously you don't know exactly what we've learned, but it has to be extremely simple and not at all fancy.
I'm not trying to cheat and have someone do my work for me, but I'm just stumped and need some clues. I'm having difficulty reaching out to my teacher (this is an online class)
We are also supposed to use the numbers in the report to do some calculations for another report. If you have any thoughts about that, it would also be helpful. I'm hoping that if I can figure out how to do this first part, I'll be able to figure out how to work with the numbers further.
I've been able to get python to bring in the .txt file and just spit out a list that is identical to what is actually in the .txt file and I've been able to get it to print one specific line. I think I'm somehow supposed to use a nested if statement to analyze and work with chunks of four lines at a time, but I'm not sure how to do that.
I got it to say "time is 12AM" by doing this:
time_line = 1
linecounter = 0
with open("Dec12.txt",'r') as f:
for line in f:
linecounter += 1
if linecounter == time_line:
print("time is",line, end='')
I got it to spit out the entire list exactly as it appears in the .txt file by doing this:
file = open ("Dec12.txt",'r')
for line in file:
num = (line)
print (num)
file.close()
If you have read this far, I am extremely grateful to you. Thank you for any thoughts or ideas you may have.