0

The bold portion is what I'm having issues with. I'm trying to sum all of the values entered by a user for every month, but I keep getting an error even when I rewrite it? (Shown at the bottom)

import statistics

months = ["January ","February ","March ", "April ", "May ","June ",
        "July ","August ","September ","October ","November ",
        "December "]

rainfall = []

for i in range( len(months) ):
    val = input("Enter the amount of rainfall for the month of " + months[i] +
                "(in inches): ")
    rainfall.append(float(val))


**print("Total amount of rainfall for the year: ", sum(rainfall))**

print("Average monthly rainfall: ", statistics.mean(rainfall))

print("The minimum amount of rainfall is ", min(rainfall), ", recorded in",
      months[rainfall.index(min(rainfall))])

print("The maximum amount of rainfall is ", max(rainfall), ", recorded in", 
      months[rainfall.index(max(rainfall))])

Error Message:

  File "/Users/Emily/Documents/Intro Python 2020/In Class Activity 5 - P1.py", line 32, in <module>
    print("Total amount of rainfall for the year: ", sum(rainfall))

TypeError: 'float' object is not callable
  • 2
    Is it possible you've shadowed the built-in `sum` function by creating a variable with the same name in a part of the code you didn't show? – Paul M. Mar 25 '20 at 02:08
  • What does `print(sum)` output in the line above? – Austin Mar 25 '20 at 02:09
  • Try printing `type(sum)` before that error line. It should display [``](https://docs.python.org/3/library/functions.html#sum). – Gino Mempin Mar 25 '20 at 02:10
  • 1
    That code, on its own, runs fine. Therefore your problem lies elsewhere. That error message is something you get when you (for example) `x = 3.14159 ; x()`, so I think we can safely assume you have a variable somewhere called `sum`. – paxdiablo Mar 25 '20 at 02:14

0 Answers0