In: Physics
In Python we will be using the below code for the problem:
rainfile=open('rainfall.txt')
for line in rainfile:
values = line.split()
#print(values)
print (values[0], 'had', values[1], 'inches of rain.')
rainfile.close( )
The following is the text from rainfall.txt
Akron 26.81
Albia 37.65
Algona 30.69
Allison 33.64
Alton 27.43
AmesW 34.07
AmesSE 33.95
Anamosa 35.33
Ankeny 33.38
Atlantic 34.77
Audubon 33.41
Beaconsfield 35.27
Bedford 36.35
BellePlaine 35.81
Belleveu 34.35
Blocton 36.28
Bloomfield 38.02
Boone 36.30
Brighton 33.59
Britt 31.54
Buckeye 33.66
BurlingtonKBUR 37.94
Burlington 36. 94
Carroll 33.33
Cascade 33.48
The cities are [0] values and the rainfall is [1] values. I need to add to the code that will find and print the average rainfall in these cities by creating a list called Iowa_rainfall_list [ ] and append all the rainfalls from values[1] to the Iowa_rainfall_list. We want to create this list Iowa_rainfall_list, so we can get the average.
I added som few lines to the given code, to get the avergare rainfall. Here is the snip.
CODE:
OUTPUT: