I have no class

Rustom Mody rustompmody at gmail.com
Sat Nov 22 22:55:08 EST 2014


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!



More information about the Python-list mailing list