beginner needs help!
D Tang
dtang5 at bigpond.net.au
Tue Apr 17 21:21:44 EDT 2001
Dear all,
I'm new to python language...and I'm trying to solve a tutorial
questions...can anyone offer me a bit of help with it?
Please show me how to do Class Suit and Class FaceValue and class Card, then
I can work out how to do class Deck. Thanks!
from string import *
from whrandom import *
import re
# The front door score - the first player to reach this wins the game
front_door = 400
# Constants denoting valid card suits as strings
validSuits = ['spades','clubs','diamonds','hearts','none']
shortSuits = ['S','C','D','H','N']
# Constants that denote valid face values for cards
validFaceValues = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
longFaceValues = ['two', 'three', 'four', 'five', 'six', 'seven', 'eight', \
'nine', 'ten','Jack', 'Queen', 'King', 'Ace']
faceCards = ['J','Q','K','A']
# A CardError represents an exception specific to this module.
# A new instance should be raised when one of the other classes is
# constructed with invalid data. Other uses are also appropriate.
# The constructor takes a string which describes what went wrong.
class CardError(Exception):
def __init__(self, e): self.__error = e
def __str__(self): return ("Card error: " + self.__error)
# A Suit represents an immutable card suit.
# The constructor takes a word which describes the suit.
# This word is a string, and may be any of validSuits or shortSuits.
# The suit 'none' is not currently used.
class Suit:
def __init__(self, s):
def __cmp__(self, other):
def longForm(self):
def __str__(self):
# A FaceValue represents an immutable value of a card (2..10, Jack..Queen).
# The constructor takes a word which names the value.
# This word is a string, and may be any of validFaceValues.
class FaceValue:
def __init__(self,s):
def __cmp__(self, other):
def __str__(self):
# A Card represents an immutable playing card.
# The constructor takes one or two arguments.
# If one argument, it is taken as a word describing a card.
# If two, they are taken as describing the face value and suit of the card.
class Card:
def __init__(self, first, second = None):
def __cmp__(self, other):
def __str__(self):
def __repr__(self): return self.__str__()
# A Deck is a sequence type and bag of cards.
# It represents an ordered collection of cards.
# The constructor takes one optional argument.
# If this argument is present, it is the initial list of cards.
class Deck:
def __init__(self, cs=[]):
def append(self, x):
def remove(self, x):
def count(self,x):
def pop(self,n=0):
def __str__(self):
def shuffle(self):
More information about the Python-list
mailing list