SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Card:
  2.     suitList = ["Clubs", "Diamonds", "Hearts", "Spades"]
  3.     rankList = ["0", "Ace", "2", "3", "4", "5", "6", "7",
  4.     "8", "9", "10", "Jack", "Queen", "King"]
  5.  
  6.     def __init__(self, rank=0, suit=0):
  7.         self.rank = rank
  8.         self.suit = suit
  9.  
  10.     # THIS IS NEEDED FOR COMPARE VARIOUS TYPES OF CARDS:
  11.     def __eq__(self, other_card):
  12.         return self.rank == other_card.rank and self.suit == other_card.suit
  13.  
  14.     def __repr__(self):
  15.         return 'Card({}, {})'.format(self.rank, self.suit)
  16.  
  17. class Deck:
  18.     def __init__(self):
  19.         self.cards = []
  20.         for suit in range(4):
  21.             for rank in range(1, 14):
  22.                 self.cards.append(Card(rank, suit))
  23.  
  24.     def removeCard(self, card):
  25.         print('Before remove: ', len(self.cards))
  26.         if card in self.cards:
  27.             self.cards.remove(card)
  28.             print('After remove: ', len(self.cards))
  29.             return True
  30.         else:
  31.             return False
  32.  
  33. deck = Deck()
  34. print(deck.removeCard(Card(1,0)))
  35.      
  36. Before remove:  52
  37. After remove:  51
  38. True
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top