Created
September 19, 2016 15:39
-
-
Save data-enhanced/693062371be01d5edd971a90a78d157f to your computer and use it in GitHub Desktop.
Python - Rounding and Formatting Numbers
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
## INTEREST CALCULATOR ## | |
Lesson("Interest Calculator (Challenge)") | |
## The formula is A = P(1+r/n)**(n*t) | |
## Create each variable separate | |
## P = Principal, r = Rate %, n = times compounded per year, t = years | |
## find How much money you will have if you invest your college tuition, $100,000 into a investment account for 40 years earning 7% interest compounded yearly. | |
##CREATE HERE## | |
P = 100000 | |
t = 40 | |
r = .07 | |
n = 1 | |
A = P*(1+r/n)**(n*t) | |
B = round(A,2) # https://gist.github.com/jackiekazil/6201722 | |
C = '{:,}'.format(B) | |
# to format output with comma for thousands separator: | |
# http://stackoverflow.com/questions/1823058/how-to-print-number-with-commas-as-thousands-separators/10742904#10742904 | |
## STOP HERE ## | |
##uncomment the print line when you are done and run the script. The correct answer should be $1,497,445.78 | |
print("You invested $%s in 2016. \nOver %s years you earned on average %1.2f percent interest.\nYou are now retired with $%s." %(P, t, r*100, C)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment