Question

In: Computer Science

Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This...

Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This assignment will give you experience on the use of the while loop and the for loop.

You will use both selection (if) and repetition (while, for) in this assignment. Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number of months that have passed since the account was established. A loop should then iterate once for every month, performing the following:

1. Ask the user for the amount deposited into the account during the month. (Do not accept negative numbers.) This amount should be added to the balance.

2. Ask the user for the amount withdrawn from the account during the month. (Do not accept negative numbers.) This amount should be subtracted from the balance.

3. Calculate the monthly interest. The monthly interest rate is the annual interest rate divided by 12. Multiply the monthly interest rate by the balance and add the result to the balance. After the last iteration, the program should display the ending balance, the total amount of deposits, the total amount of withdrawals, and the total interest earned. Note: If a negative balance is calculated at any point, a message should be displayed indicating the account has been closed and the loop should terminate.

Solutions

Expert Solution

#This program collects some data from the

#user about operations done to a saving

#account then, it presents the information

#derived from the data

totalDeposit = 0.0

totalWithdraw = 0.0

earnedInterest= 0.0

#annual Interest input

annualInterest = float(input("Enter the Annual interest Rate: "))

#input balance amount

balance = float(input("Enter the starting balance: "))

while balance<0:

print("Negative values are not allowed")

balance = float(input("Enter the starting balance: "))

#input number of months

months = int(input("Enter the number of months: "))

while months<=0:

print("months can not be 0 or less than zero")

months = int(input("Enter the number of months: "))

#Loop over all the monts to get the data

for i in range(1,months+1):

# Get the deposited value during that month.

deposited = float(input(f"Enter the deposited value during month {i}: "))

while deposited<0:

print("deposit value can not be less than zero")

deposited = float(input(f"Enter the deposited value during month {i}: "))

totalDeposit += deposited

balance += deposited

#Get the withdrawn value during that month

withdrawn = float(input(f"Enter the withdrawn value during month {i}: "))

while withdrawn<0:

print("withdrawn value can not be less than zero")

deposited = float(input(f"Enter the withdrawn value during month {i}: "))

totalWithdraw += withdrawn

balance -= withdrawn

#Negative balance close the program.

if balance <0:

print("Sorry your account is closed due to negative balance")

break

#Calculate value due to the interest rate

else:

earnedInterest += (annualInterest/12) * balance

#monthly interest rate

balance += (annualInterest/12) * balance

print("Statistics: ")

print("The Ending Balance: ",balance)

print("Total Deposit: ",totalDeposit)

print("Total Withdrawn: ",totalWithdraw)

print("Earned Interest: ",earnedInterest)











Related Solutions

This is an assignment for python. Download the code “ GradeBook.py ” You will be modifying...
This is an assignment for python. Download the code “ GradeBook.py ” You will be modifying the code to do the following: 1) create an empty dictionary named “FinalAverages” 2) In one for loop you will zip all lists together and get their individual members on each iteration. You can name these what ever you want. 3) on each iteration: Calculate the WEIGHTED average using the weights provided, and then add a new dictionary value to the dictionary “ FinalAverages...
Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and...
Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and if-else statements. Candy Calculator [50 points] The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR. The calories needed for a woman to maintain her weight is: BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 *...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1:...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1: User name Generator Write a program that prompts for and reads the user’s first and last name (separately). Then print a string composed of the first letter of the user’s first name, followed by the first five characters of the user’s last name, followed by a random number in the range 10 to 99. Assume that the last name is at least five letters...
Writing python code: Can you do for me this. The question looks bellow Overview : As...
Writing python code: Can you do for me this. The question looks bellow Overview : As a programmer, you have be asked by a good friend to create a program that will allow them to keep track of their personal expenses. They want to be able to enter their expenses for the month, store them in a file, and then have the ability to retrieve them later. However, your friend only wants certain people to have the ability to view...
Overview In this assignment you are required to implement binary code comparator using Xilinx that it...
Overview In this assignment you are required to implement binary code comparator using Xilinx that it is compatible with the MXK Seven Segment Displays. You will draw your digital logic circuit using Xilinx and then simulate it to verify the functionality of your design. Software Requirements ? Xilinx ISE 10.1 or higher Specifications Binary Code Comparator The binary code comparator is to be implemented and made compatible with the seven 7-segment displays of the board. Represent the first five digits...
In this assignment you will start with Python code that builds a 2 host network connected...
In this assignment you will start with Python code that builds a 2 host network connected by a legacy router. You will modify it such that the two hosts can send packets to each other. It requires that you understand subnet addressing and the function of a router. The network built using Miniedit on a Mininet virtual machine: python mininet/examples/miniedit.py. We need to also make 6 static routes to make the program work. This is the work that I have...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm to work along with a worked exercise from Chapter 5. Use two different looping strategies for different purposes. Prior Task Completion: 1. Read Chapter 05. 2. View Chapter 05’s video notes. 3. As you view the video, work along with each code sample in PyCharm using the Ch 5 Iteration PPT Code Samples.zip. Important: Do not skip the process of following along with the...
Describe how tuples can be useful with loops over lists and dictionaries, and give Python code...
Describe how tuples can be useful with loops over lists and dictionaries, and give Python code examples. Create your own code examples. Do not copy them from the textbook or any other source. Your descriptions and examples should include the following: the zip function, the enumerate function, and the items method.
Explain the applicability of the Uniform Commercial Code (UCC) to bank transactions Assignment Overview: In this...
Explain the applicability of the Uniform Commercial Code (UCC) to bank transactions Assignment Overview: In this writing assignment, you will explain a bank's liability when it deposits a customer's check in the wrong account. Deliverables: A 150-word (2-3 paragraph) paper Step 1: Write a short statement informing a bank of its liability when it deposits a customer's check in the wrong account. Three weeks ago, you deposited a $1,000 payroll check at your bank after having signed your name to...
This assignment will acquaint you with the use of while loops and boolean expressions. You will...
This assignment will acquaint you with the use of while loops and boolean expressions. You will create a program that acts as a score keeper of a racquet ball game between two players. The program will continually ask the user who the winner of every point is as the game is played. It will maintain the scores and declare the match is over, using these rules: (1) A game is over when a. one of the players wins 7 points...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT