-
Notifications
You must be signed in to change notification settings - Fork 0
/
25-percent-investment-calculator-with-absorbing-streak.py
92 lines (90 loc) · 3.54 KB
/
25-percent-investment-calculator-with-absorbing-streak.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
91
92
#!/usr/bin/env python3
import random
coin = ('success', 'failure', 'failure', 'failure' )
success, failure = 0, 0
rounds = 0
absorbingstreak = 0
bank = 100000000
print('***********************************************')
print('**** 25% Investment Success Simulation ****')
print('**** ****')
print('**** Starting with $100,000,000 ****')
print('***********************************************')
while True:
flip = random.choice(coin)
user_input = input('Press enter to invest $10 million, X to end the simulation:')
if user_input == 'x' or user_input == 'X':
percentagesuccess = round(success/rounds, 2)
percentagefailure = round(failure/rounds,2)
netinvestment = bank - 100000000
totalgrowth = round(((bank/100000000-1)*100), 2)
growthperperiod = round(((bank - 100000000)/rounds), 2)
print(' ')
print('**********************************')
print('***** Ending the Simulation *****')
print('**********************************')
print(' Rounds invested = {}'.format(rounds))
print(' Orig = $100000000')
print(' Bank = ${}'.format(bank))
print(' Net Income = ${}'.format(netinvestment))
print(' Total Growth = {}'.format(totalgrowth)+ '%')
print(' Growth Per Round = ${}'.format(growthperperiod))
print(' ')
print(' Success = {}'.format(success))
print(' Success Percentage = {}'.format(percentagesuccess) + '%')
print(' Failure = {}'.format(failure))
print(' Failure Percentage = {}'.format(percentagefailure) + '%')
print(' ')
break
if bank <= 0:
print(' ')
print('**********************************')
print('********* BANKRUPTCY!!! *********')
print('**********************************')
print(' ')
break
if absorbingstreak == 4:
rounds += 1
failure += 1
netinvestment = bank - 100000000
percentagesuccess = round(success/rounds, 2)
percentagefailure = round(failure/rounds,2)
print(' ')
print('*************************************************')
print(' You have lost four times in a row. Game Over.')
print(' Rounds invested = {}'.format(rounds))
print(' Net income: ${}'.format(netinvestment))
print(' ')
print(' Success = {}'.format(success))
print(' Success Percentage = {}'.format(percentagesuccess) + '%')
print(' Failure = {}'.format(failure))
print(' Failure Percentage = {}'.format(percentagefailure) + '%')
print(' ')
print('*************************************************')
print(' ')
break
if bank <= 10000000:
print(' ')
print('**********************************')
print('***** Bank Balance is Low ******')
print('**********************************')
print(' ')
if flip == 'success':
print(' ')
print('** Successful investment. You earned $40,000,000 **'.
format(flip))
success += 1
rounds += 1
absorbingstreak = 0
bank += 40000000
print(' Bank = ${}'.format(bank))
print(' Rounds invested = {}'.format(rounds))
else:
print(' ')
print("** Failed investment. You lost $10,000,000 **".format(flip))
failure += 1
rounds += 1
absorbingstreak += 1
bank -= 10000000
print(' Bank = ${}'.format(bank))
print(' Rounds invested = {}'.format(rounds))