#๐Ÿ”’ My remove_piece function is not working correctly (this time i dont know the solution)

44 messages ยท Page 1 of 1 (latest)

cold crownBOT
#

@hearty jetty

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

hearty jetty
#

the add_piece function works perfectly, but remove_piece acting up

potent quest
#

dunno what you mean by "acting up", but I wonder if you intended to put a "return" inside your for loop

hearty jetty
#

yes i did intend for that

potent quest
#

๐Ÿคท

hearty jetty
#

My remove_piece function is not working correctly (this time i dont know the solution)

true knoll
#

Did you share the remove piece code ?

#

I can only see add piece

hearty jetty
#

oh dear

#

sorry about that let me send that

#
def remove_piece(board: list[str], piece: str, column_index: int) -> bool:
    for x in range(6, -1, -1):
        if board[column_index - 1][x] == piece:
            board[column_index - 1] = board[column_index - 1].replace(piece, "-", 1)
            print(x)
            display_board(board)
            return True
    return False```
potent quest
#

I know that "acting up" means "not working as intended". What I don't know is: how did you intend it to work, and how does its actual behavior differ from that?

hearty jetty
#

it should remove the piece starting from the bottom

potent quest
#

presumably it's not displaying what you expected it to. But you've not told us what you expected it to display.

hearty jetty
#

like if i input r1

#

it will remove the piece on the first row

#

then if i type r1 again

#

it will remove the piece in the next row above that

true knoll
#

What does the x in the loop represent you seem to have 8 x 8 grid ?

hearty jetty
#

i think position in the column

#

each column has 8 position for a piece to fill

true knoll
#

Isn't 6 to -1 only 7 values tho

#

0 1 2 3 4 5 6

hearty jetty
#

yea but my string that stores it

board = ['--------', '--------', '--------', '--------', '--------', '--------', '--------', '--------']```

starts at 0, finishes at 7
#

like index 0 for the first item would be the first cell

#

index 7 for the first item would be the eight cell

true knoll
#

Yeah but you only have 6 in the loop should it be 7 ?

hearty jetty
#

hmm leme change that

#

na didnt fix anything

#

its still weird

#

there is some really weird indexing thats going on that is messing it up

true knoll
#

Okay so when i say a1 it should append add X to row 1 (not 0 but 1) and right ?

#

When i say r1 it should remove all x from row 1 ?

#

Or just the first it finds i guess

#

And what if there are no x in row 1 ?

hearty jetty
#

starting from the bottom

true knoll
#

Brb

hearty jetty
#

fixed it via string slicing.

#

!close

cold crownBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.