You are a scientist studying the rainfall in the area. The file attached has a huge list of rainfalls for the past year. Sum the values in the file and print out the result. Recall that you can convert strings to floats using the float function.
0 0 0 0 0 0 0.5 0 0 0 0 0 0.2 0 2.2 1.9 0 0 0 1.5 1.4 1.9 0 0 0.4 0 0 1.1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.7 0 0 0 0 0 0 0 0 0.4 0 0 0 0 0 0 0 0 0 1.5 0 0 0 0 0 0 0.9 0 0 0 1.4 0 2.0 2.1 0 0.2 0 0 0 0 0 0 0 0 0 0 0 1.9 1.7 0 0 0 0 0 0 0 2.9 2.8 2.9 2.6 2.4 2.5 2.6 0 0 0.8 0 1.7 1.6 0 0 0 1.6 1.9 0 0 1.0 0 0 0 0 2.8 2.6 0 0 2.3 1.6 0 0 4.1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.8 0 0 0 0 0 0.6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9 0 0 0 2.7 2.5 0 0 0 0.2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.6 0 0 0 0 0 0 1.5 0 0 0 0 0 0 0 0 0 0 0 0 1.7 0 0 0 0 0 0 0 0 0.2 0 0 0 0 1.6 1.9 1.8 1.7 1.6 1.8 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0 0 0 0 0 0 0 2.6 2.9 2.8 0 0 0 0 2.2 2.5 2.7 0 3.5 2.8 0 2.1 1.8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9 0 1.1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.4 2.9 3.2 2.3 2.5 0 1.2 0 0 0 0 0 0 0 0 0 0 0 0 0 1.6 0 0 0 0.2 0 0 0.5 0 1.9 0 2.1 1.9 2.3 0 0 0 0 0 0.8 0 0 0 0 0 0 0 0 1.7 0 0 0
Close
python
filename = "rainfall.txt"
try:
f = open(filename, 'r')
total = 0
for line in f:
total += float(line.strip())
print("Sum of all rainfall is", total)
f.close()
except FileNotFoundError:
print(filename + " does not exists!")
You are a scientist studying the rainfall in the area. The file attached has a huge...