Skip to content
Permalink
Browse files
Add files via upload
  • Loading branch information
dacostag committed May 4, 2020
1 parent f1383fb commit 2003423387bc7eb880b284edf39a6e212ff60114
Showing 1 changed file with 71 additions and 0 deletions.
71 main.py
@@ -0,0 +1,71 @@
class Calculator:
def __init__(self):
self.question_number = 0
self.total = 0

def calculator(self): # applies formula to the values
self.rate = self.rate / 100
self.monthly = self.monthly * 12
for i in range(0, self.years):
if self.total == 0:
self.total = self.account
self.total = (self.total + self.monthly) * (1 + self.rate)
print("Total amount of money you would have in your account after " + str(self.years) + " years: " + str(round(self.total, 2)))

def error(self):
if self.question_number == 1:
if self.account <= 0:
return True
else:
return False
if self.question_number == 2:
if self.monthly <= 0:
return True
else:
return False
else:
if 0 < self.rate < 100:
return False
else:
return True

def asker(self): # stores values from user inputs
if self.question_number == 0:
print("How many years will you be saving for? ")
self.years = int(input("Enter years: "))
self.question_number += 1

if self.question_number == 1:
print("How much money is currently in your account?")
self.account = float(input("Enter current amount in account: "))
if self.error():
self.asker()
else:
self.question_number += 1

if self.question_number == 2:
print("How much money are you planning on investing monthly? ")
self.monthly = float(input("Enter amount: "))
if self.error():
self.asker()
else:
self.question_number += 1

if self.question_number == 3:
print("What's the yearly interest rate of this investment?")
self.rate = int(input('Enter interest rate in percentage: '))
if self.error():
self.asker()
else:
self.question_number += 1

if self.question_number == 4:
self.calculator()


c = Calculator()
c.asker()




0 comments on commit 2003423

Please sign in to comment.