-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeckOfCards.py
More file actions
45 lines (36 loc) · 874 Bytes
/
DeckOfCards.py
File metadata and controls
45 lines (36 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import random
class DeckOfCards:
SUITS = ["Hearts", "Diamonds", "Clubs", "Spades"]
RANKS = [
"Ace",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"Jack",
"Queen",
"King",
]
def __init__(self):
self.__cards = []
self.create_deck()
def create_deck(self):
cards = [(rank, suit) for suit in self.SUITS for rank in self.RANKS]
tuple(cards)
self.__cards = cards
def shuffle_deck(self):
random.shuffle(self.__cards)
def deal_card(self):
if len(self.__cards) < 1:
return None
else:
card = self.__cards.pop()
return card
# don't touch below this line
def __str__(self):
return f"The deck has {len(self.__cards)} cards"