In: Computer Science
Answer in Python: show all code
3) Modify your code to take as input from the user the starting balance, the starting and ending interest rates, and the number of years the money is in the account. In addition, change your code (from problem 2) so that the program only prints out the balance at the end of the last year the money is in the account. (That is, don’t print out the balance during the intervening years.)
Sample Interaction:
Enter starting balance: 1000
Enter starting interest rate: 3
Enter ending interest rate: 5
Enter number of years: 5
Interest rate of 3 %:
Balance after year 5 is $ 1159.27
Interest rate of 4 %:
Balance after year 5 is $ 1216.65
Interest rate of 5 %:
Balance after year 5 is $ 1276.28
problem 2 instruction: to reference for this question:
2) For the last assignment you had to write a program that calculated and displayed the end of year balances in a savings account if $1,000 is put in the account at 6% interest for five years.
The program output looked like this:
Balance after year 1 is $ 1060.0
Balance after year 2 is $ 1123.6
Balance after year 3 is $ 1191.02
Balance after year 4 is $ 1262.48
Balance after year 5 is $ 1338.23
Modify your code so that it displays the balances for interest rates from three to five percent inclusive, in one percent intervals. (Hint: Use an outer loop that iterates on the interest rate, and an inner one that iterates on the year.)
Output:
Interest rate of 3 %:
Balance after year 1 is $ 1030.0
Balance after year 2 is $ 1060.9
Balance after year 3 is $ 1092.73
Balance after year 4 is $ 1125.51
Balance after year 5 is $ 1159.27
Code1:-
bal=int(input("Enter Starting balance: "))
startrate=int(input("Enter Starting interest rate: "))
endingrate=int(input("Enter ending interest rate: "))
years=int(input("Enter number of years: "))
for i in range(startrate,endingrate+1):
print("Interest rate of ",i,"%")
cal=bal
for j in range(1,years+1):
cal=cal+(i/100)*cal
print("Balance after year ",years,"is $",round(cal,2))
Screenshot:-
output:-
Code2:-
bal=int(input("Enter Starting balance: "))
startrate=int(input("Enter Starting interest rate: "))
endingrate=int(input("Enter ending interest rate: "))
years=int(input("Enter number of years: "))
for i in range(startrate,endingrate+1):
print("Interest rate of ",i,"%")
cal=bal
for j in range(1,years+1):
cal=cal+(i/100)*cal
print("Balance after year ",years,"is
$",round(cal,2))
Screenshot;-
Output:-