from random import randint class Bet: def __init__(self): self.nots=[-1,0] self.nums=[1, 2, 3] self.pays = 2.0 def checkWin(self, roll): return roll not in self.nots and roll in self.nums def pay(self, sim, bet, won): if won: sim.cash = sim.cash + (bet * self.pays) sim.cash = sim.cash - bet #print sim.cash def check(self, sim, roll, bet): win=roll not in self.nots and self.checkWin(roll) self.pay(sim, bet, win) class Even(Bet): def checkWin(self, roll): return roll % 2 == 0 class Odd(Bet): def checkWin(self, roll): return roll % 2 == 1 class FirstHalf(Bet): def checkWin(self, roll): return roll <= 18 class SecondHalf(Bet): def checkWin(self, roll): return roll >= 19 class FirstThird(Bet): def __init__(self): Bet.__init__(self) self.pays=3.0 def checkWin(self, roll): return roll <= 12 class RSim: def __init__(self): self.cash = 100 def sim (self, bets, rounds): for j in range(rounds): roll = randint(-1, 36) for i in bets: i.check(self, roll, 1) r=RSim() r.sim([SecondHalf(), FirstThird()], 1000) print r.cash #for i in range(100): print randint(-2, 5)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question