[Fwd: Re: [Tutor] about the function]

Brian van den Broek bvande at po-box.mcgill.ca
Mon Oct 25 06:50:12 CEST 2004


Hi Lin Jin,

you are welcome. You replied to me personally; it is late here, so I am
forwarding it to the list. That way everyone can see your more detailed
question. (You will get much better help from the entire list than from
just me ;-)

Best,

Brian vdB

-------- Original Message --------
Subject: Re: [Tutor] about the function
Date: Mon, 25 Oct 2004 08:50:44 +0800
From: Lin Jin <jinlin555 at msn.com>
To: bvande at po-box.mcgill.ca

thx for you reply.so if i want to make a tictactoe game,and i write code
like this:

def drawBoard(marks):
   """Output the board represented by marks."""
   print "0|1|2  ",marks[0],"|",marks[1],"|",marks[2]
   print "-----  ","-----"
   print "3|4|5  ",marks[3],"|",marks[4],"|",marks[5]
   print "-----  ","-----"
   print "6|7|8  ",marks[6],"|",marks[7],"|",marks[8]


def setPosition(position,symbol,marks):
   """Set the particular position to the player's mark symbol."""
   marks=marks[:int(position)]+symbol+marks[int(position)+1:]
   return marks


def playerTurn(symbol,marks):
   """Output the players'symbol choice on the board"""
   symbol=raw_input("Player ")
   position=raw_input("choose where you want to make your mark (0-8): ")
   marks=marks[:int(position)]+symbol+marks[int(position)+1:]
   return marks

print "TIC TAC TOE: "
print "0|1|2  "," | | "
print "-----  ","-----"
print "3|4|5  "," | | "
print "-----  ","-----"
print "6|7|8  "," | | "

how can i implement them in order to let players alternate turn and draws
on the board each turn.i dun know how to get the position and the symbol
from the other function
>From: Brian van den Broek <bvande at po-box.mcgill.ca>
>To: Lin Jin <jinlin555 at msn.com>
>CC: tutor at python.org
>Subject: Re: [Tutor] about the function
>Date: Sun, 24 Oct 2004 19:20:19 -0400
>
>Lin Jin said unto the world upon 2004-10-24 18:58:
> > i am new in python.just learn how to defining the function.i want to
> > know that if i define three functions.how can i use read the data from
> > one function to the other funtion.it;s like if i have function
> > draw(pic),setposition(position,pic).if i want to used the data in
> > setposition for the draw.how i could do that.
> >
> > _________________________________________________________________
> > Ãâ·ÑÏÂÔØ MSN Explorer:   http://explorer.msn.com/lccn/
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>Hi Lin Jin,
>
>I am not sure I understand your question. But this silly example might
>be helpful:
>
>def get_the_number_2():
>     return 2
>def get_the_number_3():
>     return 3
>def multiply_two_numbers(x, y):
>     return x * y
>print multiply_two_numbers(get_the_number_2(), get_the_number_3())
> >>>
>6
>
>So, one way is to use a call to one function in the argument place of
>another.
>
>You could also do:
>
>first_arg = get_the_number_2()
>second_arg = get_the_number_3()
>multiply_two_numbers(first_arg, second_arg)
>
>Are these techniques the sort of thing you were wanting?
>
>One other thing: it is much easier to read a post if a space follows
>each period. Like that. :-)
>
>Best,
>
>Brian vdB
>
>

_________________________________________________________________
ÏíÓÃÊÀ½çÉÏ×î´óµÄµç×ÓÓʼþϵͳ¡ª MSN Hotmail¡£  http://www.hotmail.com






More information about the Tutor mailing list