TypeError: range () integer end argument expected to receive a float?

I know that this was asked earlier, but the answers did not help me: /

I created a function that starts the for loop on the square of max inputs, and for all my accounts the correct code ... and yet it still requests floating point inputs.

def spiral(X, Y): x = y = 0 dx = 0 dy = 0 count = 0 for i in range(max(X, Y)**2): if (-X/2.0 < x <= X/20) and (-Y/2.0 < y <= Y/2.0): print (x, y) if x == y or (x < 0 and x == -y) or (x > 0 and x == 1-y): dx, dy = -dy, dx x, y = x+dx, y+dy 

spiral print (3.0.3.0)

And I get this error: TypeError: range() integer end argument expected, got float.

But I put 3.0 when I try to print a function ... so what am I missing?

Thanks:)

+8
source share
1 answer

Like the other comments in the comment, the problem is mainly related to the float value in the range function. Because the range function does not accept float as an argument.

 for i in range(max(int(X), int(Y))**2): 
+7
source

Source: https://habr.com/ru/post/1212762/


All Articles