-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.py
48 lines (31 loc) · 1022 Bytes
/
Card.py
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
45
46
47
48
'''
Eric Evans
a simple Card object with a rank and suit
'''
SUITS = {'C','S','H','D'}
VALUE = {'2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '\
9':9, 'X':10, 'J':11, 'Q':12, 'K':13, 'A':14}
class Card:
rank = 'X'
suit = 'C'
def __init__(self,rank,suit):
if suit[0].capitalize() not in SUITS:
raise Exception('{} is not a valid suit'.format(suit))
else:
self.suit = suit[0].capitalize()
if rank.capitalize() not in VALUE.keys():
raise Exception('{} is not a valid rank'.format(rank))
else:
self.rank = rank.capitalize()
def __getitem__(self,key):
return self._list()[key]
def __repr__(self):
return 'Card{}'.format(self._list())
def __str__(self):
return self.__repr__()
def _list(self):
return (self.rank,self.suit)
def value(self):
return VALUE[self.rank]
def short(self):
return '{}{}'.format(self.rank,self.suit)