In: Computer Science
Python
Albert Einstein famously said that compound interest is the 8th wonder of the world. Hopefully, all of you have had a finance course to teach you why it is so much more powerful than simple interest, which we programmed in class. If you are unfamiliar with compound interest, google it (note - if you google "compound interest for dummies" you will get a MUCH simpler explanation of how it works, without greek function notations!!)
Your assignment this week is to use a for loop, with the range() function to figure out compound interest on a deposit. You will ask the user for the amount of the deposit, the interest rate and the number of years and tell her how much money she has after that amount of time. Be sure to use the isnumeric function, and do NOT use an exponent to figure out compound interest - use a loop!
Python Code :
# Python code to Calculate the compound interest # take all variable(principle amount, rate and years) till # user input numerical value n = "" while not n.isnumeric(): n=input("Enter the principle amount:") n = float(n) rate ="" while not rate.isnumeric(): rate=input("Enter the rate:") rate = float(rate) years = "" while not years.isnumeric(): years=input("Enter the number of years:") years = int(years) # calculate final amount after each year for i in range(years): n=n+((n*rate)/100) print(n)
Output :
Enter the principle amount: 100
Enter the rate: 2
Enter the number of years: 2
104.04
Hope you like it
Any Query? Comment Down!
I have written for you, Please upvote the answer as it encourage us to serve you Best !