Question: This function reads the rainfall.txt file and writes out to a new file called outRainfall.txt The new file should format each line so that the

This function reads the rainfall.txt file and writes out to a new file called outRainfall.txt

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.

i have the function but could you explain how it works? Like which aspects of the function do what?

def saveRainfallData():

rainFall = open("rainfall.txt", "r")

outfile = open("outRainfall.txt", "w")

for aline in rainFall:

values = aline.split()

city = values [0]

inches = float(values[1])

outfile.write("%+25s %5.1f " % (city,inches))

rainFall.close()

outfile.close()

print("Running Q1: Rainfall data")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!