forked from EugeneArtes23/DeerhacksRepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoinFlip.py
90 lines (74 loc) · 3.18 KB
/
CoinFlip.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import random
from time import sleep
total_balance = 100
class CF:
def __init__(self, total_balance):
self.total_balance = total_balance
def play_game(self):
coin_faces = ['H', 'T']
win_streak = 0
run_state = True
while run_state:
print("Your total balance is $", self.total_balance)
# Ask player for bet
bet = 0
while True:
bet = input("How much would you like to bet?\n$")
if bet.isnumeric():
bet = float(bet)
else:
continue
if bet > self.total_balance or bet < 0:
print("Bet should not be lower or higher than your total balance!")
else:
self.total_balance = self.total_balance - bet
break
# Ask player for Heads or Tails
player_choice = ''
while True:
player_choice = input("Choose 'H' for Heads or 'T' for Tails:\n")
if player_choice != 'H' and player_choice != 'T':
print("Not a valid choice!")
else:
break
# Win/Lose after choosing
flip_coin = random.choice(coin_faces)
if player_choice == flip_coin:
print("You win!")
win_streak += 1
print("You have a win streak of", win_streak)
match win_streak:
case 1:
self.total_balance = 1*bet+self.total_balance+bet
case 2:
self.total_balance = 1.25*bet+self.total_balance+bet
case 3:
self.total_balance = 1.25*bet+self.total_balance+bet
case 4:
self.total_balance = 1.5*bet+self.total_balance+bet
case 5:
self.total_balance = 1.5*bet+self.total_balance+bet
case 6:
self.total_balance = 2*bet+self.total_balance+bet
case 7:
self.total_balance = 2*bet+self.total_balance+bet
case 8:
self.total_balance = 4*bet+self.total_balance+bet
case 9:
self.total_balance = 4*bet+self.total_balance+bet
case 10:
self.total_balance = 8*bet+self.total_balance+bet
case _:
print("That's enough bro...")
break
print("You now have a balance of $", self.total_balance)
continue
else:
print("You lose!")
print("You lost a win streak of", win_streak)
print("You lost with $", self.total_balance)
break
return self.total_balance
game = CF(total_balance)
total_balance = game.play_game()
print("$", total_balance)