a python program to read the rainfall.txt file and then write out a new file called rainfallfmt.txt . The data should be grouped on the total annual rainfall field into the following categories: [60-70], [71-80], [81-90],[91-]. Under each category, the new file should format each line so that the city is right-justified in a field that is 25 characters wide, and the rainfall data should be printed in a field that is 5 characters wide with 1 digit to the right of the decimal point. This is what I have so far; the problem is I don't know how to categorize it? Would you please help me and let me know how I can solve this problem?
================================================
# read the rainfall.txt then write out a new file called rainfall.txt
# the data should be grouped on the total annual rainfall field into the
# categories: [60-70], [71-80], [81,90], [91-]
import os.path
def main():
endofprogram = False
try:
InputFileName = input('Enter name of input file: ')
infile = open(InputFileName,'r')
OutputFileName = input('Enter name of output file: ')
# determine wether name exists
while True:
if os.path.isfile(OutputFileName):
OutputFileName = input('File Exists. Enter name again: ')
else:
outfile = open(OutputFileName,'w')
break
except IOError:
print("Error opening file - End of program")
endofprogram = True
#If there is not exception, start reading the input file
#Write the same data in formated form in new file.
if endofprogram == False:
data = []
for line in infile:
.
.# I dont know what to do in here!
.
outfile.write(data[0])
main()