错误在于,range的2个输入都必须为整型,上述代码里“math.sqrt(number)”的实际值为2.449489742783178,为浮点型,你可以在那句前面输出下该值看一下。所以会说“range() integer end argument expected, got float.”,range期待整型参数,却得到个浮点。将math.sqrt(number)外面加个强制转型,写为:“int(math.sqrt(number))”,就可以了。
"TyprError: range() integer end argument expected, got float."
Because math.sqrt(num) returns a float number, but what function range() needs is a int, so you may use
for i in range(2, int(math.sqrt(number))):
instead.
math.sqrt(number)返回的是float类型,你强制转换一下