#๐ My remove_piece function is not working correctly (this time i dont know the solution)
44 messages ยท Page 1 of 1 (latest)
@hearty jetty
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.
dunno what you mean by "acting up", but I wonder if you intended to put a "return" inside your for loop
yes i did intend for that
๐คท
"acting up" == not working as intended
My remove_piece function is not working correctly (this time i dont know the solution)
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```
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?
it should remove the piece starting from the bottom
presumably it's not displaying what you expected it to. But you've not told us what you expected it to display.
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
What does the x in the loop represent you seem to have 8 x 8 grid ?
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
Yeah but you only have 6 in the loop should it be 7 ?
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
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 ?
no only remove X from column 1
starting from the bottom
Brb
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.