Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def newdeck(n):
- assert n % 2 == 0
- cards = (['red'] * (n/2)) + (['black'] * (n/2))
- random.shuffle(cards)
- return cards
- def play():
- deck = newdeck(52)
- money = 0
- count = 0
- while deck:
- bet = False
- if count > 0:
- bet = True
- card = deck.pop()
- if bet:
- if card == 'red':
- money += 100
- else:
- money -= 100
- if card == 'red':
- count -= 1
- else:
- count += 1
- #print '%5s %5s %d' % (bet, card, money)
- return money
- total = 0
- trials = 1000
- for i in range(trials):
- total += play()
- print total / float(trials)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement