In: Computer Science
Write a program that calculates the balance of a savings account at the end of a three month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following:
After the last iteration, the program should display a final report that includes the following information:
IN PYTHON PLEASE!!
Solution:
Note: Please refer the screenshot for indentation.
Code implementation:
balance=int(input("Enter Starting balance: "))
print(balance) #prints balance entered by the user.
annual_ir=int(input("Enter Annual interest rate: "))
print(annual_ir) # prints annual_ir entered by the user.
i=0 #iteration variable.
while(i<3):
print()
print("Month:",end=" ")
print(i+1)
i+=1
month_starting_balance=balance # month_starting_balance
print("Starting balance:",end=" ")
print(month_starting_balance)
amount_deposit=int(input("Enter deposit amount: "))
print(amount_deposit) # prints amount_deposit
while(amount_deposit<0): # checks for negative value.
amount_deposit=int(input("Enter deposit amount: "))
print(amount_deposit)
balance+=amount_deposit # adds amount deposited.
print("Amount deposited:",end=" ")
print(amount_deposit)
amount_withdraw=int(input("Enter withdraw amount: "))
print(amount_withdraw) #prints amount_withdrawn
# checks for negative and amount greater than balance.
while(amount_withdraw<0 or amount_withdraw>balance):
amount_withdraw=int(input("Enter withdraw amount: "))
print(amount_withdraw)
print("Amount withdrawn:",end=" ")
print(amount_withdraw)
balance-=amount_withdraw # subtracts the withdrawn amount from
balance.
month_ending_balance=balance
monthly_interest=annual_ir/12 #monthly Interest.
interest_for_month=((month_starting_balance+month_ending_balance)/2)*monthly_interest
print("Ending balance:",end=" ")
print(month_ending_balance) # displays month end balance.
print("Interest posted:",end=" ")
print(interest_for_month) # displays interest for each month.
balance+=interest_for_month
print("Final balance:",end=" ")
print(balance) # displays balance for each month.
Code screenshot:
Code input and output screenshot: