Skip to content

Instantly share code, notes, and snippets.

@mxdi9i7
Created January 17, 2024 22:41
Show Gist options
  • Save mxdi9i7/9880ca135ce65b1e9e55284e77f76d2e to your computer and use it in GitHub Desktop.
Save mxdi9i7/9880ca135ce65b1e9e55284e77f76d2e to your computer and use it in GitHub Desktop.
for ethan week 7
m1 = [[1, 2, 3, 4], [4, 5, 6, 7], [7, 8, 9, 10], [15, 16, 17, 18]]
# write a for loop to display these numbers in this format: 1 2 3 4 5 6 7 8 9
# format: 3 2 1 6 5 4 9 8 7
# for..in
# for row in m1:
# for item in row:
# print(item, end = ' ')
# for..range: you can customize the start..end..step in a for..range loop
# for rowIndex in range(start, end, step):
# for itemIndex in range(start, end, step):
# print(..., end = ' ')
def print_matrix(matrix):
for x in range(0, len(matrix)):
row = matrix[x]
for y in range(0, len(row)):
print(row[y], end = ' ')
m2 = [['James', 'Peter', 'John'], ['Sarah', 'Vivian', 'Hannah'], ['Jon', 'Betsy', 'Nathan']]
# print_matrix(m1)
# print_matrix(m2)
tic_tac_toe = [
['x', 'o', 'x'],
['o', 'o', 'o'],
['x', 'x', 'o']
]
# print out every move on this board from left to right: x o x o x x x x o
def check_winner(player, board):
if board[0][0] == player and board[1][1] == player and board[2][2] == player:
return True
if board[0][2] == player and board[1][1] == player and board[2][0] == player:
return True
# check horizontal winner
for x in range(0, len(board)):
counter = 0
for y in range(0, len(board[x])):
if player == board[x][y]:
counter += 1
if counter == len(board[x]):
return True
# check vertical winner, programmaticall
# check diagonal winner, programmatically
return False
print(check_winner('x', tic_tac_toe))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment