-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
153 lines (134 loc) · 5.4 KB
/
main.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from buy import selectBuys
from stocks import stockManager
def askCosts() -> float:
""" Determine the users yearly or one time costs. """
totalCost = 0
print("Write the item then the cost in dollars (NA to stop).")
inputStr = input("Enter a cost: ")
while inputStr.upper() != "NA":
item, currCost = inputStr.split(' ')
totalCost += round(float(currCost), 2)
inputStr = input("Enter another cost: ")
return totalCost
def askWants() -> (list, list, list):
""" Determine the users yearly or one time wants. """
itemNames = []
prices = []
values = []
print("Respond in the form \"itemName price happinessValue\" (NA to stop).")
inputStr = input("Enter a wanted item: ")
while inputStr.upper() != "NA":
itemName, price, value = inputStr.split(' ')
itemNames.append(itemName)
prices.append(round(float(price), 2))
values.append(round(float(value), 2))
inputStr = input("Enter another wanted item: ")
return itemNames, prices, values
# Introduction
print() # new line
print("Welcome to money manager simulator!")
print("Congrats! Your financial troubles are now over.")
print("Just try not to make your account go into the negatives. ")
print("With this program you will be better informed about your finances.")
yearsToSimulate = int(input("How many years do you want to simulate: "))
print() # new line
# Net salary (income - taxes)
income = round(float(input("Enter your income per year: $")), 2)
taxes = 0
if income >= 625370:
taxes += 60789.92 + ((income - 625369) * 0.123)
elif income >= 375222:
taxes += 32523.20 + ((income - 375221) * 0.113)
elif income >= 312687:
taxes += 26082.09 + ((income - 312687) * 0.103)
elif income >= 61215:
taxes += 2695.19 + ((income - 61215) * 0.093)
elif income >= 48436:
taxes += 1672.87 + ((income - 48436) * 0.08)
elif income >= 34893:
taxes += 860.29 + ((income - 34893) * 0.06)
elif income >= 22108:
taxes += 348.89 + ((income - 22108) * 0.04)
elif income >= 9326:
taxes += 93.25 + ((income - 9326) * 0.02)
else:
taxes = income * 0.01
income = income - taxes
taxes = round(taxes, 2)
income = round(income, 2)
print(f"You have ${taxes:.2f} of income taxes, \
leaving you with ${income:.2f} to spend.")
print() # new line
# Yearly costs
print("Enter your yearly costs for the following items (in USD).")
print("Think about: Rent, Gas, Electricity, Long term goals, ...")
yearlyCosts = askCosts()
yearlyBudget = round(income - yearlyCosts, 2)
if (yearlyBudget < 0):
exit("insufficient funds\n")
else:
print(f"You can spend ${yearlyBudget:.2f} every year.")
print() # new line
# Yearly wants
print("Enter the items you want ever year (in USD).")
print("Think about: 6 flags season pass, netflix, newspaper, ...")
yearlyWants, yearlyWantsPrices, yearlyWantsValues = askWants()
print() # new line
# Major loop (1 iteration simulates 1 year)
yearlyLeftOver = 0
stockSimulator = stockManager()
print("Starting year by year simulation.\n")
for year in range(yearsToSimulate):
# Inform user
print(f"\nYear {year + 1}:")
currBudget = yearlyBudget + yearlyLeftOver
print(f"You can spend ${currBudget:.2f} in total this year")
print() # new line
# One time costs
print("Enter your costs for this year (in USD).")
print("Think about: Medical costs, Vacation, Donations, ...")
currBudget -= askCosts()
print() # new line
# Stock trading
print("These are the stocks you have.")
stockSimulator.display()
inputStr = input("Would you like to trade stocks (y/N): ")
while inputStr[0].lower() != 'n':
print(f"You have ${currBudget:.2f} left to spend.")
action, ticker, shares = input(
"Enter buy or sell, ticker, and # of shares: ").split(' ')
if action == "buy":
bought, price = stockSimulator.buy(ticker, int(shares), currBudget)
print(f"Bought {bought} shares of {ticker} at ${price:.2f}.")
currBudget -= bought * price
elif action == "sell":
sold, price = stockSimulator.sell(ticker, int(shares))
print(f"Sold {sold} shares of {ticker} at ${price:.2f}.")
currBudget += sold * price
else:
print("invalid action")
currBudget = round(currBudget, 2)
inputStr = input("Would you like to continue trading stocks (y/N): ")
print() # new line
# One time wants
print(f"You can spend ${currBudget:.2f} this year on things you want")
print("Enter the items you want this year (in USD)")
print("Think about: Trends, New pet, clothing, ...")
oneTimeWants, oneTimeWantsPrices, oneTimeWantsValues = askWants()
print() # new line
# "buy the items"
yearlyPurchases, oneTimePurchases, happiness, amountSpent = selectBuys(
currBudget, yearlyWantsPrices, yearlyWantsValues, oneTimeWantsValues, oneTimeWantsValues)
yearlyLeftOver = round(currBudget - amountSpent, 2)
print("Buy the following yearly wanted items.")
for i in yearlyPurchases:
print(yearlyWants[i])
print("Buy the following one time items.")
for i in oneTimePurchases:
print(oneTimeWants[i])
print(f"After buying the above items you will be {happiness} \
\"happy\" and will have ${yearlyLeftOver:.2f} left over for next year")
print() # new line
# Closing
print("Thank you for playing the money manager simulator!")
print("We hope you enjoyed managing your finances! ")