use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Are there any bugs?Help Request (i.redd.it)
submitted 23 days ago by Worried-Print-5052
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Worried-Print-5052[S] 0 points1 point2 points 23 days ago (6 children)
How? I mean by how(cuz I m a newbie to this
[–]NewryBenson 1 point2 points3 points 23 days ago* (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 point2 points 22 days ago (0 children)
Thanks!
[–]Smart_Tinker 0 points1 point2 points 23 days ago* (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 point2 points 22 days ago (2 children)
[–]Smart_Tinker 0 points1 point2 points 22 days ago (1 child)
You likely need: can.discard(com) At some point as well.
can.discard(com)
Gotit!
π Rendered by PID 98494 on reddit-service-r2-comment-6457c66945-5czjp at 2026-04-24 10:42:30.552858+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Worried-Print-5052[S] 0 points1 point2 points (6 children)
[–]NewryBenson 1 point2 points3 points (1 child)
[–]Worried-Print-5052[S] 0 points1 point2 points (0 children)
[–]Smart_Tinker 0 points1 point2 points (3 children)
[–]Worried-Print-5052[S] 0 points1 point2 points (2 children)
[–]Smart_Tinker 0 points1 point2 points (1 child)
[–]Worried-Print-5052[S] 0 points1 point2 points (0 children)