A Simple Tic Tac Toe Terminal Game
https://github.com/SidertheCoder/Python-Git-Repository/blob/main/TTT.py
I am currently taking a computer science course on Codecademy.com and needed to make a terminal game for my portfolio project so I decided to make a game of Tic Tac Toe.
In my code I first created a dictionary to hold what would go in each box of the Tic Tac Toe board making use of the fact that the [ ] in a list looks like a box when printed in a terminal. I then use that dictionary in the function create_grid to present the board as it currently is. Next I made a class named Player that gets the 2 player names and also checks who is going first based on a roll randomized between 1 and 6, whoever is first also gets to pick if they want X or O. After that is a win_check function that checks if any of the 8 winning combinations appear on the grid. Finally a definition to initialize game and all previous functions plays and repeats players picking where their X or O goes until the board is full or a winning combination is found and prints out an announcement of the winner.
I am still quite new to Python so I'm aware I should've used comments more, remembered to commit more often and I could've made it look cleaner but I plan to continue to work so I can do those things better. Any tips or advice is always appreciated and thank you for reading.
The above is the detailed content of A Simple Tic Tac Toe Terminal Game. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Fastapi ...

Using python in Linux terminal...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
