3

I get a error of a integer expected a float so I change it and then get the reverse saying a float can not be a integer. I had similar issues before and just changed it to have the int.

I am learning via tutorials in python27 but have for the most part got them to work in python34 via troubleshooting. This one I got stuck on.

TypeError: integer argument expected go float'

for tile in return_tiles:
    pygame.draw.circle(screen, [34, 95, 200],
    [tile.x + half - 2, tile.y + half - 2], 5 )

So I then made the change below it would usually work like the one under this one but in this case get a error

TypeError: 'float' object cannot be interpreted as a integer

   for tile in return_tiles:
        pygame.draw.circle(screen, (34, 95, 200), (int(tile.x + half -2),int(half - 2, tile.y + half - 2)), int(5))

example of how I fixed another one below that was a integer but in the case above it did not work

 pygame.draw.circle(screen, (34, 95, 200), (int(tile.x + half -2),int(half - 2, tile.y + half - 2)), int(5))

I been teaching myself by learning tutorials online but most are for earlier version 2.7 etc of python. But that has not been a problem for the most part. I been just using the the error msg and for the most part I can figure it out if not sometimes I run 2to3.py or search to find the answer.

4
  • 1
    int(half - 2, tile.y + half - 2)) seems like the brackets are not in the right place Change it to: circle(screen, (1, 2, 3), (int(tile.x+half-2), int(tile.y+half-2)), 5) Commented Jul 25, 2015 at 15:43
  • thx, pygame.draw.circle(screen, (34, 95, 200), (int(tile.x+half-2), int(tile.y+half-2)), 5) Commented Jul 25, 2015 at 15:49
  • @johntaylor now did it work Commented Jul 25, 2015 at 15:49
  • it did fix that line but the overall issue was half variable float needed to be set to a int like bakkal pointed out Commented Jul 25, 2015 at 16:05

1 Answer 1

6

I suspect your culprit is the half variable, since it involves a division, in Python 2 it'll give you an int, however in Python 3 a division will give a float unless you use the int division operator //

If you're using Python 2 tutorials, they didn't have to deal with that

Python 3

>>> 5 // 3
1
>>> 5 / 3
1.6666666666666667

So I would go look for where half is calculated, and either coerce to int with half = int(...) or use //

In pygame it's not very useful to use float for pixel dimensions, so just keep everything in int, especially when you do divisions like for half, the rest of arithmetics like tile.x + half will yield an int if both operands are ints, so there is no need to coerce

Sign up to request clarification or add additional context in comments.

2 Comments

A solution for this problem when dealing with python 2/3 compatilibity issues is to add the following line to the top of your file(s): from __future__ import division This will make division in python 2 behave like it does in python 3
I changed it from I changed it to half = Tile.width / 2 into half = int(Tile.width / 2) I got a bunch of other issues before this will run but I now understand how to fix this one going forward. thx again.

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.