[Tutor] loops

Gregor Lingl glingl@aon.at
Wed, 5 Dec 2001 02:08:29 +0100

```----- Original Message -----
From: "john public" <apython101@yahoo.com>
To: <tutor@python.org>
Sent: Wednesday, December 05, 2001 12:25 AM
Subject: [Tutor] loops

> 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?

Certainly:

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]

for i in range(9):
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]

And the next problem would be: how to
find out, if the game is over before the
ninth draw?

Gregor

P.S.: Hav a look at http://www.python.org/doc/Newbies.html

```