'Getting TypeError: 'range' object is not callable when trying to get the sum of the squares of odd numbers between 1 and 1000
I'm trying to get the sum of the squares of odd numbers between 1 and 1000, but for some reason I'm getting the error "TypeError: 'range' object is not callable" What could the issue be?
squares = []
oddnumbers = range(1,1001,2)
for number in oddnumbers:
squares.append(number**2)
mysum = oddnumbers (squares)
print("sum of squares of odd integers between 1 and 1000 is ", mysum)
Solution 1:[1]
Use keyword sum
Try:
squares = []
oddnumbers = range(1,1001,2)
for number in oddnumbers:
squares.append(number**2)
mysum = sum(squares)
print("sum of squares of odd integers between 1 and 1000 is ", mysum)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Harsha Biyani |
