OK, This is probably pretty simple, but I'm still very new to python. I appreciate the help.
I'm trying to get my program to access a text file indicated from the command line that contains some float data preceded on a line but a related year.
For example:
2010
11 21.5 18 15.2 13 17 14 0 10 16 8.6 5
2013
10.6 14.5 17.9 11.2 1.5 1.9 16 2.2 10 5.2 4.6 5
I want to ask the user to input a year, and then if the year is found in the text file, print the related data for each month.
I can't seem to get this to work.
Currently, the program will check for the year, and if it's not found it will say so, and ask again, but if it is found, it will just ask again immediately.
This is a tidied version of the part of my code:
f = open(sys.argv[1])
months = ['January', 'February', ...]
while True:
f.seek(0)
os.system('cls')
year = input("Enter year for which you want rainfall data: ")
line = f.readline().strip()
while line and line != year:
line = f.readline().strip()
if not line:
print("No rainfall data found for year {}".format(year))
input("Press Enter to continue ...")
response = input("Do it again for another year? [[y]/n] ")
if response == "n":
break
else:
rain_line = f.readline()
rain_line = rain_line.strip()
rain_line = rain_line.split()
rain_strings = list(rain_line)
rain_numbers = []
for rain in rain_strings:
rain_numbers.append(rain)
print("in {}, {} Millimeters.".format(months[1], rain_numbers[1]))
Anybody see if i'm close or way off?
I've been toying around for hours.