#๐Ÿ”’ Code review on a simple tic-tac-toe game for beginners

40 messages ยท Page 1 of 1 (latest)

stark totem
#

Hello guys, I've just started learning python; I've learn about list, 2D lists, loops and function and I've now decided to make a small tic-tac-toe game.

Can someone provide some reviews on the following code please; where can I improve my code, why, what are some of the good practices etc please:

neat martenBOT
#

@stark totem

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.

subtle minnow
#

!paste

neat martenBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

stark totem
#

sorry I couldn't paste the code here

cloud moat
#

why do you check_board at the start of every loop instead of just checking if someone won after they make a move?

#

also as a player i would rather input a coordinate rather than inputting the row and then the column

idle estuary
#

1-9

stark totem
cloud moat
#

the output would be the same but it would do it more efficiently

stark totem
#

yeah I see, ok noted

stark totem
#

thanks !

cloud moat
#

you could include spaces after the O and X

#

OXO -> O X O

stark totem
#

yeah I found that confusing too

cloud moat
#

to keep the row length closer

stark totem
#

will do that

idle estuary
#

less visually noisy

cloud moat
#

would only work in a monospaced font

stark totem
# cloud moat the output would be the same but it would do it more efficiently

by the way, will checking the board after each move inside the function choose_tile itself will increase efficiency, because, at the end, aren't we doing the same thing, just instead of calling check_board in the function choose_tile at the end, we call it in the main itself but which is also after a player's move

cloud moat
#

i dont think lines 30 and 31 actually do anything

    col = 0```
idle estuary
#

either way just ```
X . .
. . O
. . .

stark totem
cloud moat
stark totem
stark totem
#

oh ok

cloud moat
#

you could add error checking to the input if you wanted
ValueError: invalid literal for int() with base 10: 'a'

stark totem
#

yeah will do the handling of error/exceptions later on when I tackle the topic handling exceptions

cloud moat
#
game_board = [[0,0,0],
              [0,0,0],
              [0,0,0]]``` why store 0 when you could store `'_'`
#

which wouldnt require the later conversion

stark totem
neat martenBOT
#
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.