In: Computer Science
write a python script to calculate 401k with compounding interest
Taking principle amount ,P =401k
This program will ask for the rate of interest and no.of years(n) to the user and takes the input.
The value of principle amount after n years with interest compunded anually is outputted to the user.
P=401*1000
# reading inputs from user using input() method of type int()
r=float(input("Enter rate of interest : "))
n=int(input("Enter no.of times interest is compounded per year : "))
t=int(input("Enter no.of year : "))
# Calculating amount after principle compounded n times in t years at interest rate of r
A= pow(P*(1 + (r/n)),n*t)
# Printing the final amount
print("Amount after principle compounded {}".format(n)+" times in {}".format(t)+" years at interest rate of {}".format(r)+" is : {}".format(A))
I have calculated the compunded amount "A" of principle "P" at interest rate of "r" in "t" years at "n" times per year is
I have provide comments in the code to explain steps. Feel free to comment for any queries or if you want any modifications in the code.
I have tested the code for different inputs and the code is working fine. I am providing an output screenshot for your reference.
Thank you :)