for HCC classes taught by Rylan Schubkegel
Previously your projects have been simple enough to complete in one week, but now it’s time to turn up the heat 🔥
During the next two weeks, you will program a game of Tic, Tac, Toe to test your knowledge of functions. This week, you must submit a program that matches the following specifications:
print_column
piece
piece
will be one of the following values:
None
if no player has played on this cell yet'X'
if the X player has played on this cell'O'
if the Y player has played on this cellpiece
without printing a newline characterprint_row
columns
, which will be a list of 3 valuesprint_column()
3 times, once for each piece in columns
|
characterprint_board
rows
, which will be a list of 3 valuesprint_row()
3 times, once for each value in rows
-
charactersprint_board()
to print a test board to the console, like so:
print_board([
['X', None, None],
[None, 'O', 'X'],
['O', None, None],
])
Which will result in somthing like the following output:
-------------
| X | | |
-------------
| | O | X |
-------------
| O | | |
-------------
So far, each time we have called print()
it has automatically added a newline character to the end of whatever string we pass as an argument. However, according to the Python 3 docs we can provide a named argument for the parameter end
to change what gets printed at the end of our string. Here is an example:
print('Hello, ', end='')
print('World!')
print('This is a new line.')
Which prints the following output:
Hello, World!
This is a new line.
Named arguments are a more advanced feature in Python. If you are curious, this article dives into different types of arguments and parameters.