ABOUTPYTHON
Python, often referred to as the "programming language for everyone," is a
versatile, user-friendly, and highly popular programming language. Its story
is one of simplicity, versatility, and a community that embraces inclusivity.
Python is an interpreted, object oriented, high level programming language
with dynamic semantics. Its high level built in data- structures, combined
with dynamic typing and dynamic binding makes it very attractive for rapid
application development as well as for use as a scripting or glue language
to connect existing components together. Python’s simple, easy to learn
syntax emphasizes readability and therefore reduces the cost of
programme maintenance. Python supports modules and packages which
encourages programme modularity and code reuse. The python interpreter
and the extensive standard library are available in source or binary form
without charge for all major platforms and can be freely distributed
HISTORY OF PYTHON
Python was created in the late 1980s by Guido van Rossum, a Dutch
programmer. Guido's vision was to design a language that emphasized
code readability, a concept he called "executable pseudo-code." Python's
first official release, Python 0.9.0, occurred in February 1991. Since then, it
has undergone numerous developments and refinements, and it is now
maintained by the Python Software Foundation. Its name, a nod to the
British comedy group Monty Python, reflects the language's philosophy of
keeping things fun and entertaining.
FEATURES OF PYTHON:
● Readability: Python's design is known for its readability. Its syntax,
which employs indentation and clear, concise code structure, makes
it exceptionally easy to understand. This readability is one of
Python's most celebrated features, making it an ideal choice for both
beginners and experienced developers.
● Versatility: Python's versatility is unmatched. It's widely used in web
development, data analysis, artificial intelligence, scientific
computing, and much more. Libraries and frameworks like Django,
Flask, and TensorFlow extend Python's capabilities to a variety of
domains.
● Community: Python's strength lies in its dedicated and vibrant
community. This community fosters a collaborative, welcoming, and
inclusive environment. Python enthusiasts are always ready to offer
assistance and guidance, making it easier for newcomers to learn
the language.
● Open Source: Python is open source, which means it's free to use,
modify, and distribute. This openness promotes accessibility and
encourages contributions from a diverse range of developers.
● Cross-Platform Compatibility: Python is compatible with major
operating systems like Windows, macOS, and Linux. This cross-
platform compatibility allows developers to work on different systems
without major adjustments.
● Rich Standard Library: Python boasts a comprehensive standard
library that covers a wide range of functionalities. These built-in
modules save developers time and effort by providing pre-written
code for common tasks.
PYTHON BEING A FRIENDLY LANGUAGE
Python is renowned for its friendliness due to several reasons. Its
readability makes it accessible for beginners who are just starting their
programming journey. The welcoming community offers support and
learning resources, which further lowers the entry barrier. Python's
versatility enables developers to work on diverse projects, whether it's
web development, data analysis, or creating games. This flexibility
accommodates different interests and goals, making Python feel like a
welcoming language for all.
In summary, Python is a programming language with a rich history, a
multitude of features, and an inclusivity that sets it apart. Its humane,
reader-friendly design, coupled with a supportive community, makes it
an ideal choice for individuals of all backgrounds and skill levels.
Whether you're a beginner or a seasoned developer, Python's
embrace of simplicity and versatility ensures a warm welcome for all
who seek to explore the world of programming.
OBJECTIVEOFTHEPROJECT
The objective of this project is to let the students apply the programming
knowledge into a real world situation and expose the students how
programming skills help in developing a good software
Some key points are as follows
● Utilizing modern software tools for programming games
● Applying object oriented programming principles effectively when
developing small to medium sized problems
● Write effective procedural code to solve small to medium sized
problems
● Demonstrate a breadth of knowledge in computer science as
exemplified in the area of software development
● Demonstrate ability to conduct a research or applied computer
science project, requiring writing and presentation skills which
exemplify scholarly style in computer science.
ABOUTTHEGAME
A Tic-Tac-Toe game created in Python is a classic and straightforward
implementation of this timeless two-player strategy game. In this Python-
based rendition, the game typically runs in a console or terminal window,
allowing players to take turns marking Xs and Os on a 3x3 grid.
HOWTHEGAMEWORKS
● Board Setup: The game begins with an empty 3x3 grid, and two
players are assigned their symbols, usually X and O.
● Turn-Based Gameplay: Players take turns making moves. They input
the row and column where they want to place their symbol, and the
program updates the board accordingly.
● Winning Condition: The game checks after each move if a player has
won by getting three of their symbols in a row horizontally, vertically,
or diagonally. If a winning condition is met, the game announces the
winner.
● Tie Game: If all the spaces on the board are filled and there is no
winner, the game ends in a tie.
● Continued Play: Players have the option to start a new game or exit
the program once the current game is finished.
KEY FEATURES:
● Simple Interface: Tic-Tac-Toe in Python typically employs a text-
based interface, making it accessible and easy to play in a terminal.
● Two-Player Interaction: The game is designed for two players, who
can take turns using the same computer.
● Logic and Rules: Python's logic and conditional statements are used
to validate moves, check for wins, and ensure the game adheres to
the rules.
● Easy to Implement: Due to its simplicity, Tic-Tac-Toe is often a
beginner-friendly project for those learning Python, teaching
fundamental concepts like conditionals and loops.
● Customization: More advanced versions may offer features like
customizable symbols, larger game boards, and various winning
conditions.
SOURCECODE
from tkinter import * import
random def next_turn(row,
column):
global player if buttons[row][column]['text'] == "" and
check_winner() is False:
if player == players[0]:
buttons[row][column]['text'] = player
if check_winner() is False: player =
players[1]
label.config(text=(players[1]+"
turn"))
elif check_winner() is True:
label.config(text=(players[0]+" wins"))
elif check_winner() == "Tie":
label.config(text="Tie!")
else:
buttons[row][column]['text'] = player
if check_winner() is False: player =
players[0]
label.config(text=(players[0]+"
turn")) elif check_winner() is True:
label.config(text=(players[1]+"
wins"))
elif check_winner() == "Tie":
label.config(text="Tie!")
def check_winner():
for row in range(3):
if buttons[row][0]['text'] == buttons[row][1]['text'] ==
buttons[row][2]['text'] != "":
buttons[row][0].config(bg="green")
buttons[row][1].config(bg="green")
buttons[row][2].config(bg="green")
return True
for column in range(3):
if buttons[0][column]['text'] == buttons[1][column]['text'] ==
buttons[2][column]['text'] != "":
buttons[0][column].config(bg="green")
buttons[1][column].config(bg="green")
buttons[2][column].config(bg="green")
return True
if buttons[0][0]['text'] == buttons[1][1]['text'] == buttons[2][2]['text'] != "":
buttons[0][0].config(bg="green")
buttons[1][1].config(bg="green")
buttons[2][2].config(bg="green")
return True
elif buttons[0][2]['text'] == buttons[1][1]['text'] == buttons[2][0]['text'] != "":
buttons[0][2].config(bg="green")
buttons[1][1].config(bg="green")
buttons[2][0].config(bg="green")
return True
elif empty_spaces() is False:
for row in range(3):
for column in range(3):
buttons[row][column].config(bg="yellow")
return "Tie"
else: return
False
def empty_spaces():
spaces = 9
for row in range(3):
for column in range(3):
if buttons[row][column]['text'] != "":
spaces -= 1
if spaces == 0:
return False
else: return True def
new_game(): global player player
= random.choice(players)
label.config(text=player+" turn") for
row in range(3):
for column in range(3): buttons[row]
[column].config(text="",bg="#F0F0F0")
window = Tk()
window.title("Tic-Tac-Toe")
players = ["x","o"] player =
random.choice(players) buttons
= [[0,0,0],
[0,0,0],
[0,0,0]]
label = Label(text=player + " turn", font=('consolas',40))
label.pack(side="top")
reset_button = Button(text="restart", font=('consolas',20),
command=new_game)
reset_button.pack(side="top")
frame = Frame(window)
frame.pack()
for row in range(3):
for column in range(3):
buttons[row][column] = Button(frame, text="",font=('consolas',40),
width=5, height=2,
command= lambda row=row, column=column:
next_turn(row,column)) buttons[row]
[column].grid(row=row,column=column) window.mainloop()
OUTPUT SCREEN:
CONCLUSION
In wrapping up this Python Tic-Tac-Toe project, we've successfully created
a classic two-player game that combines simplicity with strategic thinking.
Through this project, we've not only demonstrated our proficiency in
Python programming but also our ability to design and implement a
functional and interactive application.
This game showcases the essential elements of programming – user
input, conditional statements, loops, and the logic necessary to validate
moves, determine wins, and handle ties. We've created a user-friendly
experience within a console interface, enabling players to enjoy the game
while practicing their strategic skills.
Beyond the technical aspects, this project emphasizes the importance of
problem-solving, user experience, and game dynamics. It serves as a
testament to our programming skills, as well as our ability to deliver a
classic game in a modern format.
As we conclude this project, we can take pride in our achievement and
look forward to further challenges in the world of Python programming and
beyond. Whether we choose to enhance this Tic-Tac-Toe game or embark
on entirely new projects, the knowledge and skills gained here will serve
as a solid foundation for our continued journey in the realm of software
development.
BIBLIOGRAPHY
1. Computer Science book by Sumita Arora class 11
2. Computer Science book by Sumita Arora class 12
CERTIFICATE
This is to certify that Kukil Chandra Doley of Class XII
Science A1 of Gurukul Grammar Senior Secondary School,
Guwahati has satisfactorily conducted and completed his
Investigatory
Project on Computer Science titled “tic-tac-toe game in
Python” under the guidance and supervision of Mr. Kapil Deva
Goswami. This project is completely authentic and not a copy
from any source .
We wish him success in life.
SIGNATURE OF EXTERNAL SIGNATURE OF INTERNAL
SIGNATURE OF PRINCIPAL
ACKNOWLEDGEMENT
I am deeply grateful for the invaluable support and guidance I have
received in the successful completion of this project. I would like to extend
my heartfelt thanks to the individuals who have played a crucial role in this
endeavor.
I extend my thanks to the Central Board of Secondary Education (CBSE)
for providing us with a structured and comprehensive curriculum that has
enabled us to undertake projects like this. The board's commitment to
quality education is greatly appreciated.
I extend my sincere appreciation to Dr. B. K. Bhuyan, our esteemed
Principal at Gurukul Grammar Senior Secondary School. His visionary
leadership and unwavering support have been a constant source of
inspiration. I am grateful for his commitment to fostering academic
excellence and for providing us with a platform to grow and excel.
My sincere thanks also go to our guide teacher, Mr. Kapil Deva Goswami,
for her mentorship and invaluable insights throughout this project. His
dedication, patience, and guidance have been instrumental in shaping the
project.
I would also like to express my heartfelt gratitude to my parents. Their love,
encouragement, and unwavering belief in my abilities have been my pillar
of strength.
This project is a testament to the collective effort, guidance, and support of
all these individuals and institutions. I am profoundly grateful for their
contributions to my academic and personal growth.
Kukil Chandra Doley
(CLASS XII, A1)