![](/img/trans.png)
[英]Getting TypeError: 'range' object is not callable when trying to get the sum of the squares of odd numbers between 1 and 1000
[英]use the sum method to get the sum of the squares of odd numbers between 1 and 1000
n=1000
squares = n
for x in range(1,n+1,2):
square = x**2
squares.append(square)
mysum=(squares)
print("sum of squares of odd integers between 1 and ", n, " is ", mysum)
我创建这个循环是为了列出 1 到 1000 之间奇数的平方和。不完全确定将什么设置为“平方”值,因为我收到了响应“AttributeError: 'int' object has没有属性“附加””。
抱歉,如果这听起来很愚蠢。 我是 Python 的新手。
下面将为您提供从 1 到 999 的所有奇数平方的总和。
sum(x**2 for x in range(1,1000, 2))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.