forked from abinash-mudbhari/Coin-Flip-Simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand.py
56 lines (48 loc) · 1.51 KB
/
rand.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
import random
# main function that executes codes for toss
def main():
fee = 0.001450354
bankroll = 1000
heads = 0
tails = 0
longest_head_streak = 0
longest_tail_streak = 0
current_streak = 0
last_flip = None
counter = 0
while bankroll > 0:
bet = round(random.uniform(0.05, 100), 1)
print(f"Your random bet amount is: {bet:.2f} TON")
flip = random.randint(0, 1) # 0 for heads, 1 for tails
if flip == 0 : # -
bankroll -= bet * 0.95 - fee
print(f"- Bankroll {bankroll:.2f}.")
heads += 1
if last_flip == 0:
current_streak += 1
else:
current_streak = 1
longest_head_streak = max(longest_head_streak, current_streak)
last_flip = 0
else: # +
bankroll += bet - fee
print(f"+ Bankroll {bankroll:.2f}.")
tails += 1
if last_flip == 1 :
current_streak += 1
else:
current_streak = 1
longest_tail_streak = max(longest_tail_streak, current_streak)
last_flip = 1
counter += 1
print("Counter:", counter)
if bankroll <= 0:
print("Your bankroll is depleted! Game over.")
break
print("\nGame Over!")
print("-:", heads)
print("+:", tails)
print("Longest - streak:", longest_head_streak)
print("Longest + streak:", longest_tail_streak)
# calling the function
main()