I have no class
Seymore4Head
Seymore4Head at Hotmail.invalid
Sat Nov 22 22:18:06 EST 2014
On Sat, 22 Nov 2014 19:09:27 -0800 (PST), Rustom Mody
<rustompmody at gmail.com> wrote:
>On Sunday, November 23, 2014 8:17:24 AM UTC+5:30, Seymore4Head wrote:
>> What do I need to do to make a and b have different values?
>> import random
>> class RPS:
>> throw=random.randrange(3)
>> a=RPS
>> b=RPS
>>
>> print ("a ",a.throw)
>> print ("b ",b.throw)
>> if a.throw == b.throw:
>> print("Tie")
>> elif (a.throw - b.throw)%3==1:
>> print("a Wins")
>> else:
>> print("b Wins")
>>
>> ---------
>> I tried:
>>
>> class RPS:
>> def __init__(self):
>> self.throw=random.randrange(3)
>>
>> AttributeError: type object 'RPS' has no attribute 'throw'
>
>Works as far as I can see:
>
>import random
>class RPS:
> def __init__(self):
> self.throw=random.randrange(3)
>-----------------
>>>> a = RPS()
>>>> a.throw
>0
>>>> a = RPS()
>>>> a.throw
>2
>>>> a = RPS()
>>>> a.throw
>2
It works when you remember to include the ()
I am still making rookie mistakes.
Thanks
More information about the Python-list
mailing list