9

I know this has been asked before, but the answers did not help me :/

I created a function that runs a for loop over the squared max of the inputs, and by all accounts my code is correct...and yet it still asks for float 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

print spiral(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 and print the function...so what am I missing?

Thanks :)

7
  • 1
    You're passing in floats for the values of X and Y, pass in integers instead. Commented Feb 6, 2015 at 2:49
  • this is how I call the function: print spiral(3.0, 3.0) Commented Feb 6, 2015 at 2:50
  • 1
    @Chef1075 -- Exactly. 3.0 has type float, not int. :-). Commented Feb 6, 2015 at 2:50
  • 1
    for i in range(max(int(X), int(Y))**2): Commented Feb 6, 2015 at 2:53
  • That worked. So I read it as...expecting float got integer. Exactly opposite. Commented Feb 6, 2015 at 2:54

1 Answer 1

9

Like others said in the comment, the problem is mainly because of the float value in range function. Because range function won't accept float type as an argument.

for i in range(max(int(X), int(Y))**2):
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.