-
Notifications
You must be signed in to change notification settings - Fork 1
/
Card.py
58 lines (45 loc) · 1.16 KB
/
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
49
50
51
52
53
54
55
56
57
58
import random
class Card:
def __init__(self):
'''
Constuctor
'''
list1=['\u2665','\u2600','\u2663','\u2666']
random.shuffle(list1)
self.suit=list1[0]
thenum=random.randint(0,1)
if thenum==0:
self.number = random.randint(1,10)
else:
list2=['K','Q','J']
random.shuffle(list2)
self.number = list2[0]
def __str__(self):
return str(self.number)+self.suit
def __len__(self):
return len(str(self))
def sum(arr):
'''
Returns the sum of all the cards in a given array
'''
tot=0
for card in arr:
tot+=card.getvalue()
return tot
def getvalue(self):
'''
Returns the numerical value of a card
'''
value=0
if len(self)==2:
if self.number=='K':
value=13
elif self.number=='Q':
value=12
elif self.number=='J':
value=11
else:
value = self.number
else:
value = 10
return value