-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompoundloops.py
More file actions
65 lines (53 loc) · 1.9 KB
/
compoundloops.py
File metadata and controls
65 lines (53 loc) · 1.9 KB
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
##Name; Mark Dymek
##Purpose: Compute compound interest on deposits over times.
##Date: 4/4/25
#Setup Constant
NUMBER_MONTHS = ",.2f"
#data validation and input
while True:
try:
fDeposit = float(input("Please enter your deposit as a positive non-zero number:"))
if fDeposit < 0:
print("You did not follow the rules i don't accept zero or negative numbers:")
continue
break
except ValueError:
print("Please enter a valid number:")
while True:
try:
fInterest = float(input("Please enter your interest rate as a positive non-zero number:")) / 100 / 12
if fInterest < 0:
print("You did not follow the rules i don't accept zero or negative numbers:")
continue
break
except ValueError:
print("Please enter a valid number:")
while True:
try:
iMonths = int(input("Please enter how many months you are saving:"))
if iMonths < 1:
print("You did not follow the rules i don't accept zero or negative numbers:")
continue
break
except ValueError:
print("Please enter a valid number:")
while True:
try:
fGoal = float(input("Please enter your goal it can be zero:"))
if fGoal < 0:
print("You did not follow the rules i don't accept negative numbers:")
continue
break
except ValueError:
print("Please enter a valid number:")
faccount_Bal = fDeposit
for current_Month in range (1, iMonths +1):
faccount_Bal += fInterest * faccount_Bal
print(f"After {current_Month} months your balance is ${faccount_Bal:{NUMBER_MONTHS}}")
faccount_Bal= fDeposit
iloop_Count = 0
while faccount_Bal < fGoal:
fmonthlyInterest = fInterest * faccount_Bal
faccount_Bal += fmonthlyInterest
iloop_Count += 1
print(f"it will take {iloop_Count} months to reach the goal of ${fGoal:{NUMBER_MONTHS}}")