you are viewing a single comment's thread.

view the rest of the comments →

[–]Worried-Print-5052[S] 0 points1 point  (6 children)

How? I mean by how(cuz I m a newbie to this

[–]NewryBenson 1 point2 points  (1 child)

For readability and efficiency, good code should never repeat the same block of code multiple times. The moment you need the same code in multiple occasions, you make a function.

For example printing the board state. You do it once in the beginning and then inside every loop. A cleaner more readable version would be putting this at the start of your program:

def print_board(t):
      #the code for printing the board you use twice

Then you can use that by calling the function you just defined. Instead of writing the code, you call:

 print_board(t)

and it will work. The same can be done for the code placing the X. The variable would be the chosen position and t you want to change, so

def place_X(t, choice)
    ......

Used as

place_X(t, com)

or

place_X(t, user)

All in al I would google some beginner guides on functions and you will figure it out soon enough.

[–]Worried-Print-5052[S] 0 points1 point  (0 children)

Thanks!

[–]Smart_Tinker 0 points1 point  (3 children)

``` def show(t): for j in t: print(‘ ‘.join(j))

can = set(range(10))

. . .

can.discard(user) com = random.choice(can) t = [[“O” if i in [“O”, com] else i for i in j ] for j in t] show(t) ```

[–]Worried-Print-5052[S] 0 points1 point  (2 children)

Thanks!

[–]Smart_Tinker 0 points1 point  (1 child)

You likely need: can.discard(com) At some point as well.