-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabouchere1.py
45 lines (34 loc) · 942 Bytes
/
labouchere1.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
#!user/bin/env python
import sys, random
args = sys.argv
def gamble(sequence, balance):
"""Labouchère betting."""
# Won
if len(sequence) < 1:
print("You won!")
return balance
# If the sequence is of length 1, the bet is the number in the sequence.
# Otherwise, it is the first number added to the last number.
if len(sequence) == 1:
bet = sequence[0]
else:
bet = sequence[0] + sequence[-1]
print()
print("Bet:", bet)
print()
# Lost the entire round
if bet > balance:
print("You lost!")
return balance
won = input("Won? ")
won = True if won.lower() == "y" else False
if won:
return gamble(sequence[1:-1], balance + bet)
else:
return gamble(sequence + [bet], balance - bet)
def main():
sequence = [2, 5, 3, 2, 5, 3]
balance = 100
gamble(sequence, balance)
if __name__=="__main__":
main()