Tic-Tac-Toe Judge

Lab Python Advanced 30 points

Read a 3×3 board (three lines of X, O, .). Print X wins, O wins, draw (full board, no winner) or in progress.

Input

Three lines.

Output

One line.

Example

Input

XXX
O.O
...

Output

X wins
Sample input available Sample output available
Editor
Python

Hints

Collect all 8 lines: 3 rows, 3 columns, 2 diagonals.

A player wins if "XXX" or "OOO" is one of them.

Solution explanation

Turning the board into a list of lines makes the win check a single membership test.

Show solution
board = [input() for _ in range(3)]
lines = board + ["".join(col) for col in zip(*board)]
lines += ["".join(board[i][i] for i in range(3)), "".join(board[i][2 - i] for i in range(3))]
for player in "XO":
    if player * 3 in lines:
        print(f"{player} wins")
        break
else:
    print("in progress" if any("." in row for row in board) else "draw")
Output
Answer
HOME LEARN COMMUNITY DASHBOARD