Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|
||
|
||
|
||
|