diff --git a/main.py b/main.py new file mode 100644 index 0000000..9677040 --- /dev/null +++ b/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() + + + +