forked from davehunt00/UW_python_class_demo.code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckerboard.py
More file actions
40 lines (30 loc) · 818 Bytes
/
Copy pathcheckerboard.py
File metadata and controls
40 lines (30 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env python
#
# This simulates a checkerboard or a chess board
def set_square_color ( a, r, c ):
"This sets the square color to what it is supposed to be"
a[r][c] = "*" if (r+c)%2 == 0 else " "
def return_checkerboard() :
"""This function returns an 8x8 checkboard. The white spaces are white and
the black spaces are "*" """
a=[]
for r in range(8):
a.append([])
for c in range(8) :
a[r].append([])
set_square_color( a, r, c)
return a
def print_checkerboard( b ) :
"This prints an 8x8 checkboard"
for r in range(8) :
for c in range(8) :
print b[r][c],
print
a = return_checkerboard()
print_checkerboard(a)
print
a[0][0] = "Q"
a[1][2] = "Q"
a[2][4] = "Q"
a[3][6] = "Q"
print_checkerboard(a)