0

I was checking a project that i have to turn in (it's a battleship game) and for some reason when it runs "through" the section bellow it says "can't assign function call" when it's a copy paste of a piece of just above (with a couple changes) and it gives no error. Do you see the error?

 '''
 elif y == "v":
 if a + 3 > 4:
 return "put the boat higher, here it leaves the board"
 else:
 board(a)(b) = "V"
 a = a + 1
 board(a)(b) = "V"
 a = a + 1
 board(a)(b) = "V"
 return board 
 '''
theduck
2,61713 gold badges20 silver badges24 bronze badges
asked Jan 6, 2020 at 18:05
1
  • 2
    board(a)(b) = "V" should probably be board[a][b] = "V", if you're accessing elements of a data structure. Commented Jan 6, 2020 at 18:08

2 Answers 2

1

First of all, I highly recommend you to use python 3, read this.

And I don't know what is board, so I will answer for two cases.

  1. board is not a function, nested python list
    In this case, just change () to [] to access array.
  2. board is a function
    In this case, you're definitely wrong. board() is a function call and will return function result. So, you cannot assign "V" into your function call. This is pretty natural.

Now, check out what is your case and happy coding.

answered Jan 6, 2020 at 18:14
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe instead of accessing a matrix with the [] operator you are making calls with (). So try replacing board(a)(b) with board[a][b] but without more information is really hard to tell.

answered Jan 6, 2020 at 18:08

1 Comment

@PauFrancoToda no problem man, if it solves your problem consider select it as the accepted answer.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.