MCPcopy Create free account
hub / github.com/geekcomputers/Python / main

Function main

Tic-Tac-Toe Games/tic-tac-toe6.py:131–175  ·  view source on GitHub ↗

Run a series of Tic-Tac-Toe games.

()

Source from the content-addressed store, hash-verified

129
130
131def main() -> None:
132 """Run a series of Tic-Tac-Toe games."""
133 player1 = input("Player 1, Enter the name: ")
134 player2 = input("Player 2, Enter the name: ")
135 cur_player = player1
136
137 player_choice: Dict[str, str] = {"X": "", "O": ""}
138 options: List[str] = ["X", "O"]
139 score_board: Dict[str, int] = {player1: 0, player2: 0}
140
141 print_scoreboard(score_board)
142
143 while True:
144 print(f"Turn to choose for {cur_player}")
145 print("Enter 1 for X")
146 print("Enter 2 for O")
147 print("Enter 3 to Quit")
148
149 try:
150 choice = int(input())
151 except ValueError:
152 print("Wrong Input!!! Try Again\n")
153 continue
154
155 if choice == 1:
156 player_choice["X"] = cur_player
157 player_choice["O"] = player2 if cur_player == player1 else player1
158 elif choice == 2:
159 player_choice["O"] = cur_player
160 player_choice["X"] = player2 if cur_player == player1 else player1
161 elif choice == 3:
162 print("Final Scores")
163 print_scoreboard(score_board)
164 break
165 else:
166 print("Wrong Choice!!!! Try Again\n")
167 continue
168
169 winner = single_game(options[choice - 1])
170
171 if winner != "D":
172 score_board[player_choice[winner]] += 1
173
174 print_scoreboard(score_board)
175 cur_player = player2 if cur_player == player1 else player1
176
177
178if __name__ == "__main__":

Callers 1

tic-tac-toe6.pyFile · 0.70

Calls 2

print_scoreboardFunction · 0.85
single_gameFunction · 0.85

Tested by

no test coverage detected