-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.py
49 lines (32 loc) · 960 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
49
# sample test from Fluent Python
import collections
from random import choice
Card = collections.namedtuple('Card',['rank','suit'])
class FrenchDeck:
ranks = [str(n) for n in range(2,11)] + list('JQKA')
suits = 'spades diamonds clubs hearts'.split()
def __init__(self):
self._cards = [Card(rank,suit) for suit in self.suits
for rank in self.ranks]
def __len__(self):
return len(self._cards)
def __getitem__(self, position):
return self._cards[position]
deck = FrenchDeck()
print(len(deck))
print('First card in the deck is',deck[0])
print('Last card in the deck is',deck[51])
print('Ramdom card is', choice(deck))
#print the full deck
print(deck[0:51])
for card in deck:
print(card)
def fib(n):
a, b = 0, 1
while a<n:
print(a, end=' ')
a, b = b, a+b
print() # just prints a blank line
fib(1000)
# quick digression
print('End')