"""Calculator for calculating the life time for stocks, taking into account the recession or stagnation"""
class Calc:
def __init__(self, life_price, starting_funds, recession_level, inflation):
self.life_price = life_price
self.starting_life_price = life_price
self.funds = starting_funds
self.starting_funds = starting_funds
self.recession_level = (recession_level ** (1 / 12)) / 100
self.inflation = (inflation ** (1 / 12)) / 100
self.stagnation_monthly_counter = 0
self.recession_monthly_counter = 0
def stagnation(self):
while self.funds > 0:
self.funds -= self.life_price
self.life_price = self.life_price * (1 + self.inflation)
self.stagnation_monthly_counter += 1
def recession(self):
self.funds = self.starting_funds
self.life_price = self.starting_life_price
while self.funds > 0:
self.funds -= self.life_price
self.funds = self.funds * (1 - self.recession_level)
self.life_price = self.life_price * (1 + self.inflation)
self.recession_monthly_counter += 1
def main():
print("Please input your monthly life price:")
life_price = int(input())
print("Please input your starting funds:")
starting_funds = int(input())
print("Please input deflation level, percentages are entered in integer format, 5% must enter as 5:")
recession_level = int(input())
print("Please input yearly inflation, percentages are entered in integer format, 5% must enter as 5:")
inflation = int(input())
calculation = Calc(life_price, starting_funds, recession_level, inflation)
calculation.stagnation()
calculation.recession()
print("Your starting funds:", starting_funds, "Your life price:", life_price, sep="\n")
print("Life in stagnation in years:", calculation.stagnation_monthly_counter/12, sep="\n")
print("Life in recession in years:", calculation.recession_monthly_counter / 12, sep="\n")
if __name__ == '__main__':
main()