Python Project
Python Project
KUTTANELLUR
CLASS 12
COMPUTER SCIENCE
PROJECT
Submitted by:
Agnus Elsa Binu
MINI GAMES
COMPUTER SCIENCE AGNUS ELSA BINU
24627403
2023-2024
COMPUTER SCIENCE
1 Aim 5
2 Acknowledgement 6
3 Introduction 7
4 Platforms used 8
5 Input 9
6 Result
16
7 Bibliography 22
AIM
Game 1 : Hangman
import random
def get_word():
try:
with open('hangman.txt', 'r') as file:
words = file.read().splitlines()
return random.choice(words).upper()
except FileNotFoundError:
print("The file hangman.txt was not found.")
return None
def display_hangman(tries):
stages = [
"""
-----
| |
| O
| \\|/
| |
| / \\
-
""",
"""
-----
| |
| O
| \\|/
| |
| /
-
""",
"""
-----
| |
| O
| \\|/
| |
|
-
""",
"""
-----
| |
| O
| \\|
| |
|
-
""",
"""
-----
| |
| O
| |
| |
|
-
""",
"""
-----
| |
| O
|
|
|
-
""",
"""
-----
| |
|
|
|
|
-
"""
]
return stages[tries]
def play():
word = get_word()
if word is None:
return
word_completion = '_' * len(word)
guessed = False
guessed_letters = []
guessed_words = []
tries = 6
if __name__ == "__main__":
play()
def print_board(board):
for i, row in enumerate(board):
print(" | ".join(row))
if i < 2:
print("-----------")
def check_tie(board):
return all(cell != ' ' for row in board for cell in row)
def tic_tac_toe():
board = [[' ' for _ in range(3)] for _ in range(3)]
current_player = 'X'
for _ in range(9):
print_board(board)
row, col = get_move(board, current_player)
board[row][col] = current_player
if check_win(board, current_player):
print_board(board)
print(f"Player {current_player} wins!")
return
current_player = 'O' if current_player == 'X' else 'X'
if check_tie(board):
print_board(board)
print("It's a tie!")
return
if __name__ == "__main__":
tic_tac_toe()
RESULT
Game 1 : Hangman
Text file named 'hangman.txt' is
created
and text 'Rosslers' is added
Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 13:03:39) [MSC v.1935 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
-----
| |
|
|
|
|
-
________
-----
| |
|
|
|
|
-
_____E__
-----
| |
| O
|
|
|
-
_____E__
-----
| |
| O
| |
| |
|
-
_____E__
-----
| |
| O
| |
| |
|
-
R____ER_
-----
| |
| O
| |
| |
|
-
RO___ER_
-----
| |
| O
| \|
| |
|
-
RO___ER_
-----
| |
| O
| \|
| |
|
-
RO___ER_
-----
| |
| O
| \|
| |
|
-
ROSS_ERS
-----
| |
| O
| \|/
| |
|
-
ROSS_ERS
-----
| |
| O
| \|/
| |
|
-
ROSSLERS