Professional Documents
Culture Documents
Python
Chapter Six
Functions: The Tic-Tac-Toe Game
Objectives
• Write your own functions
• Accept values into your functions through
parameters
• Return information from your functions through
return values
• Work with global variables and constants
• Create a computer opponent that plays a strategy
game
instructions.py
value = 10
print "In the global scope, value is:", value, "\n"
read_global()
print "Back in the global scope, value is:", value, "\n"
value = 10
shadow_global()
print "Back in global scope, value is still:", value
value = 10
change_global()
print "Back in the global scope, value is now:", value
global_reach.py
Guide to Programming with Python 33
Mutable Sequences Can Be Changed
Inside Functions
def change_list(the_list):
the_list[1] = "changed"
my_list = ["same", "same", "same"]
print my_list
change_list(my_list)
print my_list
tic-tac-toe.py
(run only)
ask_yes_no(question),
ask_yes_no(question), ask_number(question,
ask_number(question, low,
low, high),
high), legal_moves(board)
legal_moves(board)
tic-tac-toe.py