443,767 Members | 1,995 Online
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

# just need help with a card game

 P: 8 I got my code to work be the print out go's down on a angle is there anyway to stop this from happing. P.S sorry for taking up your time Expand|Select|Wrap|Line Numbers class Card:       suitList = ["Hearts", "Diamonds", "Clubs", "Spades"]     rankList = ["Invalid", "Ace", "2", "3", "4", "5", "6", "7",                 "8", "9", "10", "Jack", "Queen", "King"]       def __init__ (self, suit=0, rank=1):         if suit >= 0 and suit <= 3:             self.suit = suit         else:             self.suit = 0         if rank >= 1 and rank <= 13:             self.rank = rank         else:             self.rank = 1       def __str__(self):         return self.rankList[self.rank] + " of " + self.suitList[self.suit]       def __cmp__(self, other):         if self.rank > other.rank:             return 1         if self.rank < other.rank:             return -1         if self.suit > other.suit:             return 1         if self.suit < other.suit:             return -1         return 0   class Deck:       def __init__(self):         self.cards = []          for suit in range(4):             for rank in range(1,14):                 self.cards.append(Card(suit, rank))       def __str__(self):         s = ""         for i in range(len(self.cards)):                     s = s + (" " * i) + str(self.cards[i]) + "\n"         return s       def printDeck(self):         for card in self.cards:             print card     def main():       deck1 = Deck()     print "Original deck:"     print deck1     main() if some one can help me that will be gr8 May 22 '07 #1
5 Replies

 P: 8 o sorry and i need to add spaces between them as well :-( May 22 '07 #2

 Expert Mod 2.5K+ P: 2,851 'Deck' method: Expand|Select|Wrap|Line Numbers     def __str__(self):         return '\n'.join([str(self.cards[i]) for i in range(len(self.cards))]) May 22 '07 #3

 P: 8 thank you so much i need that help May 23 '07 #4

 Expert Mod 2.5K+ P: 2,851 thank you so much i need that help You are welcome. I am pleased to help. May 23 '07 #5

 Expert Mod 2.5K+ P: 2,851 Actually, I like this better: Expand|Select|Wrap|Line Numbers ....def __iter__(self):         for card in self.cards:             yield card       def __str__(self):         return '\n'.join([str(c) for c in self]) May 23 '07 #6