[Tutor] The Card Game
Christopher King
g.nius.ck at gmail.com
Thu Jun 30 21:43:29 CEST 2011
I would go with __cmp__ which covers them all. 1 for greater, 0 for equal,
-1 for less than.
On Thu, Jun 30, 2011 at 5:35 AM, Alan Gauld <alan.gauld at btinternet.com>wrote:
>
> "Vincent Balmori" <vincentbalmori at yahoo.com> wrote
>
>> I keep getting a Type Error since for the moment since the
>> values of the cards cannot be compared due to their
>> types.
>>
>
> Please send the complete error text sincethat will tell us
> where to look etc.
>
> I am thinking of creating a Card_Value class that will give each rank
>> and suit a certain value. If there is also a more elegant way of handling
>> some of the code in the main section that will be welcome.
>>
>
> You can get cards to compare themselves by adding a few
> more "magic methods". Then you can do stuff like
>
> if card1 < card2:
> # ....
> elif card2 > card1:
> # ....
> else:....
>
> The methods you need to create are
> __gt__(), __lt__(), __eq__(), __le__(), __ge__()
>
> for
>
> ,<,==,<=,>=
>>
>
> operations.
>
> BTW, In your code you have a comparison using = instead of ==.
> That will fail.
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ______________________________**_________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110630/85308932/attachment-0001.html>
More information about the Tutor
mailing list