Re: [Tutor] random.choice() problem

2013-06-23 Thread Peter Otten
Dave Angel wrote: > On 06/23/2013 02:18 AM, Jack Little wrote: >> I am trying to use random.choice for a text based game. I am using >> windows 7, 64-bit python. Here is my code: >> >> def lvl2(): >> print "COMMANDER: Who should you train with?" >> trn=random.choice(1,2) >> if trn==

Re: [Tutor] random.choice() problem

2013-06-23 Thread Dave Angel
On 06/23/2013 02:18 AM, Jack Little wrote: I am trying to use random.choice for a text based game. I am using windows 7, 64-bit python. Here is my code: def lvl2(): print "COMMANDER: Who should you train with?" trn=random.choice(1,2) if trn==1: lvl2_1() print "S

Re: [Tutor] random.choice() problem

2013-06-22 Thread Steven D'Aprano
On 23/06/13 16:18, Jack Little wrote: I am trying to use random.choice for a text based game. I am using windows 7, 64-bit python. Here is my code: def lvl2(): print "COMMANDER: Who should you train with?" trn=random.choice(1,2) [...] Here is my error: File "C:\Users\Jack\Deskto

[Tutor] random.choice() problem

2013-06-22 Thread Jack Little
I am trying to use random.choice for a text based game. I am using windows 7, 64-bit python. Here is my code: def lvl2():     print "COMMANDER: Who should you train with?"     trn=random.choice(1,2)     if trn==1:         lvl2_1()         print "Squad One!"     elif trn==2:         lvl2_2()      

Re: [Tutor] random.choice()

2008-07-02 Thread John Fouhy
On 03/07/2008, Alan Gauld <[EMAIL PROTECTED]> wrote: > "John Fouhy" <[EMAIL PROTECTED]> wrote > > you can instead say: > > > > try: > > foo() > > except TypeError: > > # do something else > This makes slightly more sense, although a TypeError seems a bit > too vague, if it had bveen a Callab

Re: [Tutor] random.choice()

2008-07-02 Thread Alan Gauld
"John Fouhy" <[EMAIL PROTECTED]> wrote otherwise. this will be removed for Python 3.x because you can just use hasattr(obj, '__call__'). I was about to go BOO HISS because callable() is much more readable than hasattr() but... you can instead say: try: foo() except TypeError: # do

Re: [Tutor] random.choice()

2008-07-02 Thread John Fouhy
On 03/07/2008, wesley chun <[EMAIL PROTECTED]> wrote: > on a related note, currently in Python, there is a callable() Boolean > function that returns True if the object's callable and False > otherwise. this will be removed for Python 3.x because you can just > use hasattr(obj, '__call__'). I

Re: [Tutor] random.choice()

2008-07-02 Thread wesley chun
> > It seems to me that Wes is saying only that all function objects are > > callable, not that all callable objects are functions. > > Wesley said that function objects have a "heaping distinction" of > being callable. Only he can say for sure what that means; I took it to > mean that being ca

Re: [Tutor] random.choice()

2008-07-02 Thread Kent Johnson
On Wed, Jul 2, 2008 at 11:50 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > It seems to me that Wes is saying only that all function objects are > callable, not that all callable objects are functions. Wesley said that function objects have a "heaping distinction" of being callable. Only he can say

Re: [Tutor] random.choice()

2008-07-02 Thread Dick Moores
At 03:46 AM 7/2/2008, Kent Johnson wrote: On Wed, Jul 2, 2008 at 3:54 AM, wesley chun <[EMAIL PROTECTED]> wrote: > in the former, you have a function object. it's just like any other > Python object, but with one heaping distinction: it's callable -- > this means that u can slap on a pair of p

Re: [Tutor] random.choice()

2008-07-02 Thread Kent Johnson
On Wed, Jul 2, 2008 at 3:54 AM, wesley chun <[EMAIL PROTECTED]> wrote: > in the former, you have a function object. it's just like any other > Python object, but with one heaping distinction: it's callable -- > this means that u can slap on a pair of parentheses after the object > and execute it

Re: [Tutor] random.choice()

2008-07-02 Thread Dick Moores
At 12:54 AM 7/2/2008, wesley chun wrote: ok, someone has to be the bad guy and show an example of equivalent code that's more difficult to read: choice([use_for_float_demo, use_for_integer_demo])() seriously tho, the bottom line of what people have been telling you is that for the function (or

Re: [Tutor] random.choice()

2008-07-02 Thread wesley chun
ok, someone has to be the bad guy and show an example of equivalent code that's more difficult to read: choice([use_for_float_demo, use_for_integer_demo])() seriously tho, the bottom line of what people have been telling you is that for the function (or method) foo(): def foo(): : there is

Re: [Tutor] random.choice()

2008-07-01 Thread Dick Moores
At 06:23 AM 7/1/2008, Cédric Lucantis wrote: Le Tuesday 01 July 2008 15:04:11 Dick Moores, vous avez écrit : > At 05:43 AM 7/1/2008, Tim Golden wrote: > >Dick Moores wrote: > >>So I want to randomly choose between them. I thought that I might > >>be able to use choice() to do that. So, > >>

Re: [Tutor] random.choice()

2008-07-01 Thread Cédric Lucantis
Le Tuesday 01 July 2008 15:04:11 Dick Moores, vous avez écrit : > At 05:43 AM 7/1/2008, Tim Golden wrote: > >Dick Moores wrote: > >>So I want to randomly choose between them. I thought that I might > >>be able to use choice() to do that. So, > >> (bunch of functions here) > >>if __name__ == '_

Re: [Tutor] random.choice()

2008-07-01 Thread Tim Golden
Dick Moores wrote: At 05:43 AM 7/1/2008, Tim Golden wrote: Dick Moores wrote: So I want to randomly choose between them. I thought that I might be able to use choice() to do that. So, (bunch of functions here) if __name__ == '__main__': choice([use_for_float_demo(), use_for_integer_de

Re: [Tutor] random.choice()

2008-07-01 Thread Dick Moores
At 05:52 AM 7/1/2008, Cédric Lucantis wrote: Le Tuesday 01 July 2008 14:38:36 Dick Moores, vous avez écrit : > I'm writing a demonstration version of a program which does things > with integers, and with floats, which are randomly generated. I want > to also randomly pick whether the integer side

Re: [Tutor] random.choice()

2008-07-01 Thread Dick Moores
At 05:43 AM 7/1/2008, Tim Golden wrote: Dick Moores wrote: So I want to randomly choose between them. I thought that I might be able to use choice() to do that. So, (bunch of functions here) if __name__ == '__main__': choice([use_for_float_demo(), use_for_integer_demo()]) I find that w

Re: [Tutor] random.choice()

2008-07-01 Thread Cédric Lucantis
Le Tuesday 01 July 2008 14:38:36 Dick Moores, vous avez écrit : > I'm writing a demonstration version of a program which does things > with integers, and with floats, which are randomly generated. I want > to also randomly pick whether the integer side, or the float side is > demonstrated next. I h

Re: [Tutor] random.choice()

2008-07-01 Thread Tim Golden
Dick Moores wrote: So I want to randomly choose between them. I thought that I might be able to use choice() to do that. So, (bunch of functions here) if __name__ == '__main__': choice([use_for_float_demo(), use_for_integer_demo()]) I find that what's gets run each time is BOTH of

[Tutor] random.choice()

2008-07-01 Thread Dick Moores
I'm writing a demonstration version of a program which does things with integers, and with floats, which are randomly generated. I want to also randomly pick whether the integer side, or the float side is demonstrated next. I have 2 functions, use_for_integer_demo() and use_for_float_demo(), a

Re: [Tutor] random.choice function

2008-01-19 Thread Remco Gerlich
Hi, This line: ch = "So good to see you!","How are you?","Everything good today?","Glad you're here!".split(" ") Creates a tuple with 4 elements: 1. "So good to see you!" 2. "How are you?" 3. "Everything good today?" and 4. "Glad you're here!".split(" "), which is equal to ["Glad","you're", "he

Re: [Tutor] random.choice function

2008-01-19 Thread Alan Gauld
"Cecilia Grahn" <[EMAIL PROTECTED]> wrote > I am trying to make a script which returns a random string: > > ch = "So good to see you!","How are you?","Everything good > today?","Glad you're here!".split(" ") To python this line has 4 expressions which Pyhon will assign as a tuple to ch. The firs

[Tutor] random.choice function

2008-01-19 Thread Cecilia Grahn
Hi, this is my first mail and I apologize if I got something wrong =) I am trying to make a script which returns a random string: #hello.py # Get the user's name and print a friendly hello import random, string name = raw_input("Your name please:") ch = "So good to see you!","How are you?","Everyt