int object is not callable only appears randomly

2024/11/16 22:37:35

Sometimes this code works just fine and runs through, but other times it throws the int object not callable error. I am not real sure as to why it is doing so.

for ship in ships:vert_or_horz = randint(0,100) % 2for size in range(ship.size):if size == 0:ship.location.append((random_row(board),random_col(board)))else:# This is the horizontal placingif vert_or_horz != 0 and ship.size > 1:ship.location.append((ship.location[0][0], \ship.location[0][1] + size))while(ship.location[size][1] > len(board[0])) or \(ship.location[size][1] < 0):if ship.location[size][1] > len(board[0]):ship.location[size][1]((ship.location[0][0], \ship.location[0][1] - size))if ship.location[size][1] < 0:ship.location[size][1]((ship.location[0][0], \ship.location[0][1] + size))# This is the vertical placingif vert_or_horz == 0 and ship.size > 1:ship.location.append((ship.location[0][0] + size, \ship.location[0][1]))while(ship.location[size][1] > len(board[0])) or \(ship.location[size][1] < 0):if ship.location[size][1] > len(board[0]):ship.location[size][1] \((ship.location[0][0] - size, \ship.location[0][1]))if ship.location[size][1] < 0:ship.location[size][1] \((ship.location[0][0] + size, \ship.location[0][1]))

Here is the traceback:

Traceback (most recent call last):File "python", line 217, in <module>File "python", line 124, in create_med_gameship.location[size][1]((ship.location[0][0], \
TypeError: 'int' object is not callable
Answer

You are trying to call (use the ..(...) syntax) on an integer here:

ship.location[size][1]((ship.location[0][0], \ship.location[0][1] - size))

ship.location[size][1] is an integer, and you are trying to call it by passing in the tuple (ship.location[0][0], ship.location[0][1] - size) as the arguments.

Your code makes this mistake in more than one place; other examples include

ship.location[size][1]((ship.location[0][0], \ship.location[0][1] + size))

and

ship.location[size][1] \((ship.location[0][0] - size, \ship.location[0][1]))

and

ship.location[size][1] \((ship.location[0][0] + size, \ship.location[0][1]))

The backslash there still joins the physical line into a logical line, so the (...) calls still apply to the integers.

It is not clear to me what you wanted to do with that expression, however, so I can't offer any remedy here.

https://en.xdnf.cn/q/120277.html

Related Q&A

scraping css values using scrapy framework

Is there a way to scrap css values while scraping using python scrapy framework or by using php scraping. any help will be appreaciated

Access dict via dict.key

I created a dict source = {livemode: False}. I thought its possible to access the livemode value via source.livemode. But it doesnt work. Is there a way to access it that way?As a not source[livemode]…

Function not returning anything

My viewdef login(request):c = {}c.update(csrf(request))return render_to_response(request, login.html, c)def auth_view(request):username = request.POST.get (username, )password = request.POST.get (passw…

My entry box always returns PY_VAR1 value!!though Im using the .get function

please take a look at my code, its really simple I need to take the value from the entry box and use it in my program and when pressing the add button I print it ,it keeps giving me this value PY_VAR1…

Arthimatic Quiz Not Accepting Correct Answers

I am attempting to make an arithmetic quiz, but have run into this issue: Even if I input the correct answer, it seems to ignore the correct answer code and go straight to the incorrect answer code. Ba…

Linux - Check if python script is running in screen and run if not [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 1…

Making Phonebook in python : i want to get this screen by fixing my current code

I made my code like below....But as i input the data such as spam & number, previous data is deleted.So id like to make multiple value in one key... (i think using list is kinda good method)For exa…

Adding enemies to a pygame platformer

Im new to pygame and trying to make a platformer game thats based on this tutorial: http://programarcadegames.com/python_examples/show_file.php?file=platform_scroller.pyI cant quite figure out how to …

Tips for cleaning up a challenges answer? Weighted Sum of Digits [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 8 years ago.Improve…

Get a variable as filename from python script and use it in a batch script [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 5 years ago.Improve…