I have no class

Seymore4Head Seymore4Head at Hotmail.invalid
Sun Nov 23 05:19:56 CET 2014


On Sat, 22 Nov 2014 19:55:08 -0800 (PST), Rustom Mody
<rustompmody at gmail.com> wrote:

>On Sunday, November 23, 2014 9:06:03 AM UTC+5:30, Seymore4Head wrote:
>> Now I am trying to add a dictionary, but it is broke too.
>> 
>> How do I fix:
>> class RPS:
>>     key={0:"rock", 1:"paper",2:"scissors"};
>>     def __init__(self):
>>         self.throw=random.randrange(3)
>>         self.key=key[self.throw]
>
>Maybe you want this?
>
>class RPS:
>    key ={0:"rock", 1:"paper", 2:"scissors"}
>    def __init__(self):
>        self.throw=random.randrange(3)
>        self.key=RPS.key[self.throw]
>
>Whether reusing 'key' like this is a good idea is another matter!

That works.
Thanks



More information about the Python-list mailing list