In: Computer Science
Write a Python program that will calculate how much money you will have when you invest a given amount of money over a set number of years with a given interest rate. The program takes as user input how much money to invest and the yearly interest rate and calls a calculateEarnings function using those two inputs as the parameters initialMoney and interestRate. Both of the user inputs should be able to be entered in decimal numbers. The calculateEarnings function should print out the amount of money you will have after 1 year, 10 years, 20 years, and 30 years, each value on a new line. The output should be precise to two decimal places. Calculate the total amount of money using compound interest, calculated yearly. The formula for this is below – note that 6% interest would be entered as 0.06 for interestRate in the formula but the user enters it as a percentage in the input: total Money = initial amount * (1 + interest rate)^ number of years. How much money are you investing? 10000 >>>What is the yearly interest rate (%)? 6.0 After 1 year: 10600.00 After 10 years: 17908.48 After 20 years: 32071.35 After 30 years: 57434.91
#Code in text
def calculateEarnings(money,rate):
year=1
amount_after_one = float(money)*(pow((1 + float(rate) / 100.0), year))
print("After 1 ear :%.2f "%amount_after_one)
year=10
amount_after_ten =float(money)*(pow((1 + float(rate) / 100.0), year))
print("After 10 year :%.2f "%amount_after_ten)
year=20
amount_after_twenty =float(money)*(pow((1 + float(rate) / 100.0), year))
print("After 20 year : %.2f"%amount_after_twenty)
year=30
amount_after_thirty =float(money)*(pow((1 + float(rate) / 100.0), year))
print("After 30 year : %.2f"%amount_after_thirty)
#Main
money = input("How much money are you investing? ")
interest_rate=input("What is the yearly interest rate (%)? ")
calculateEarnings(money,interest_rate)
#############################################
#Output
How much money are you investing? 10000
What is the yearly interest rate (%)? 6
After 1 ear :10600.00
After 10 year :17908.48
After 20 year : 32071.35
After 30 year : 57434.91
//Screen shot for indentation