forked from infx598g-s16/04-13-python2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterest.py
More file actions
32 lines (23 loc) · 1.17 KB
/
interest.py
File metadata and controls
32 lines (23 loc) · 1.17 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
# Prompt the user for an Initial Balance (and save to a variable)
# use the float() function to convert the input into a number.
balance = float(input("Initial balance: "))
# Prompt the user for an Annual Interest % (and save to a variable)
# use the float() function to convert the input into a number
interest = float(input("Annual interest % "))
# change the percentage number into a decimal (e.g. 6 turns into .06, 5 turns into .05, etc).
# remember to save your new value to a variable!
interest = interest/100
# Prompt the user for a Number of years (and save to a variable)
# use the int() function to convert the input into an integer
years = int(input("Years: "))
# Calculate the total value following the formula.
# You can use multiple steps and variables if necessary.
# Note that n = 12
new_balance = balance*(1+(interest/12))**(12*years)
# Calculate the interest earned based on the above value and the initial balance
interest_earned = new_balance - balance
# Output the interest earned
output = "Interest earned in "+str(years)+" years: $"+str(interest_earned)
print(output)
# Output the total value
print("Total value after "+str(years)+" years: $"+str(new_balance))