id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

chanr@sfusd.edu > winner
prev  |  next  |  chance

An array, called arr, with 9 elements in it is given. It represent the current board state of a tic tac toe game: arr[0] is the upper left arr[4] is the middle center arr[8] is the lower right
| . 0. | . 1 . | 2. |
-------------------- | . 3 . | . 4 . | 5 . |
-------------------- | . 6 . | . 7 . | 8 . | Complete the python program below that checks for a winner. There are 3 ways to win. 3 in a row (going left and right) 3 in a column (going up and down) and diagonal (start upper left going to lower right and vise versa) 0 represents an unoccupied position 1 represents an X is present 2 represent a O is present


winner([1, 1, 1, 0, 0, 0, 0, 0, 0]) → 1
winner([1, 0, 0, 1, 0, 0, 1, 0, 0]) → 1
winner([1, 1, 0, 0, 0, 0, 0, 0, 0]) → 0

...Save, Compile, Run (ctrl-enter)

def winner(arr):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 100 Post-solution available

Copyright Nick Parlante 2017 - privacy