I. Using Python: Assume that you are investing certain amounts in your savings a
ID: 3870837 • Letter: I
Question
I. Using Python: Assume that you are investing certain amounts in your savings account that yields certain interest. Write a Python program that computes the amount of money you will have in your account when you retire using the following formula: a=p(1+r)n p is the original amount invested (i.e., the principal) r is the annual interest rate (eg, .05 stands for 5%) n is the number of vears a is the amount on deposit at the end of the nth year The computed amount should be based on the following inputs: i. The original amount invested (the principal). This is a decimal number and may be any non- negative number. If a negative number is entered, the value is to be rejected and the user will be required to enter an acceptable value. Loop until a valid value is input. ii. Annual interest rate as a percent. The number must be 0 or greater, any other value will be rejected and as above, the user must be polled until a valid number is input. iii. Number of years until you retire, it must be a whole number (integer) in the range 1 to 70. Any number outside of this range is to be rejected and the user will be required to enter the value again, this repeat must be done until a valid number is input.Explanation / Answer
import math
def calculateAmount():
while True:
principal = int(input('Enter original amount invested: '))
if(principal <=0 ):
print(" Enter non negative and non zero value")
else:
break;
while True:
rate = int(input('Enter rate of interest: '))
if(rate <=0 ):
print(" Enter non negative and non zero value")
else:
break;
while True:
years = int(input('Enter number of years: '))
if(years <=0 or years >70 ):
print(" Enter non negative and non zero value")
else:
break;
amount = principal * (math.pow((1+rate), years))
print(" Total amount after retirement is: ", amount)
if __name__ == "__main__": calculateAmount()