[Tutor] loops
john public
apython101@yahoo.com
Tue, 4 Dec 2001 15:25:02 -0800 (PST)
I am a beginning programmer. Here is my my first
program for tic tac toe. It works BUT, a simple loop
would shorten this code considerably. Is there a way
to tell the program to go to the line:
n = input("which sqaure")
once it gets to the end of the first cycle?
Thanks!!
a,b,c,d,e,f,g,h,i =1,2,3,4,5,6,7,8,9
square = ['a','b','c','d','e','f','g','h','i']
print square[0],square[1],square[2]
print square[3],square[4],square[5]
print square[6],square[7],square[8]
n = input("which square?")
s = raw_input("who gets the square?")
square[n-1] = s
print square[0],square[1],square[2]
print square[3],square[4],square[5]
print square[6],square[7],square[8]
# end of first part, can we loop here?
# can we create functions and modules to shorten the
code?
n = input("which square?")
s = raw_input("who gets the square?")
square[n-1] = s
print square[0],square[1],square[2]
print square[3],square[4],square[5]
print square[6],square[7],square[8]
n = input("which square?")
s = raw_input("who gets the square?")
square[n-1] = s
print square[0],square[1],square[2]
print square[3],square[4],square[5]
print square[6],square[7],square[8]
n = input("which square?")
s = raw_input("who gets the square?")
square[n-1] = s
print square[0],square[1],square[2]
print square[3],square[4],square[5]
print square[6],square[7],square[8]
n = input("which square?")
s = raw_input("who gets the square?")
square[n-1] = s
print square[0],square[1],square[2]
print square[3],square[4],square[5]
print square[6],square[7],square[8]
n = input("which square?")
s = raw_input("who gets the square?")
square[n-1] = s
print square[0],square[1],square[2]
print square[3],square[4],square[5]
print square[6],square[7],square[8]
n = input("which square?")
s = raw_input("who gets the square?")
square[n-1] = s
print square[0],square[1],square[2]
print square[3],square[4],square[5]
print square[6],square[7],square[8]
n = input("which square?")
s = raw_input("who gets the square?")
square[n-1] = s
print square[0],square[1],square[2]
print square[3],square[4],square[5]
print square[6],square[7],square[8]
n = input("which square?")
s = raw_input("who gets the square?")
square[n-1] = s
print square[0],square[1],square[2]
print square[3],square[4],square[5]
print square[6],square[7],square[8]
__________________________________________________
Do You Yahoo!?
Buy the perfect holiday gifts at Yahoo! Shopping.
http://shopping.yahoo.com