Editor

Tic-Tac-Toe Result

Programs with input · Advanced · about 18 min

Read a tic-tac-toe board as three lines of three characters each: X, O, or - for an empty square. Print one of these:

  • X wins or O wins if that player has three in a row, across, down or corner to corner
  • Draw if every square is filled and nobody has won
  • Not finished if there are empty squares and nobody has won

No board has two winners.

The prompts inside input() are not checked, only what you print.

Examples

You type:

XXX
OO-
---

The program prints:

X wins

You type:

XOX
XOO
OXX

The program prints:

Draw
row1 = input("Row 1: ")
# Read the other two rows, then print the result
The solution opens after your first Check.