Question

In: Computer Science

need to add this withdrawal and balance function to the script below: Calculate the Balance -...

need to add this withdrawal and balance function to the script below:

Calculate the Balance - Withdrawal

If the action is Withdrawal ‘W’, use the withdrawal function to remove funds from the account

Hint – The formatter for a float value in Python is %f. With the formatter %.2f, you format the float to have 2 decimal places. For example:

print("Account balance: $%.2f" % account_balance)

Withdrawal Information

Withdraw Input

userchoice = input ("What would you like to do?\n")
userchoice = 'W'
withdrawal_amount = 100

Withdraw Output

What would you like to do?
How much would you like to withdraw today?
Withdrawal amount was $100, current balance is $600.25

ATM Summary Feedback Available

If you would like our automated system to review your code and give you some feedback on your project before you submit for a grade, just click the Help Me! button below.

Help Me!

  1. You will need to define a function called withdrawal.
  2. Request from the user the amount to be withdrawn. This value should be stored in a variable called withdrawal_amount. Use both the input and float methods in order to ensure the withdrawal_amount is a float value
  3. Ensure the withdrawal_amount is not greater than the account_balance.
    1. If the withdrawal_amount is greater than the `account_balance`, print the following message:

      withdrawal_amount is greater than your account balance of account_balance

      Ensure you display the withdrawal amount and the account balance with the '$' and two decimal points.
  4. If the withdrawal amount is less than or equal to the account_balance then calculate a new account balance.
  5. The calculation for withdrawing funds from the account is account_balance = account_balance - withdrawal_amount
  6. Print print the following message:

    Withdrawal amount was withdrawal_amount, current balance is account_balance

Need to add the Withdrawal amount to this program:

import sys # importing the sys library

# account balance

account_balance = float(500.25)

# PPrint the balance

# This is a custom function, it returns the current balance upto 2 decimal places

def printbalance():

print('Your current balance:')

return account_balance

# the function for deposit

# This is a custom function

def deposit():

# takes in input for deposit amount

deposit_amount = float(

input("How much would you like to deposit today?\n"))

balance = account_balance + deposit_amount # calculates balance

print("Deposit was $%.2f, current balance is $%.2f" %

(deposit_amount, balance)) # prints out the balance

# function for withdraw

# this is a custom function

def withdraw():

# takes in the withdraw amount

withdraw_amount = float(input("Enter amount to withdraw"))

if(withdraw_amount > account_balance): # checks whether the amount is more than balance or not

print("$%2f is greater than account balance $%2f\n" %

(withdraw_amount, account_balance)) # if yes then

else:

balance = account_balance - withdraw_amount

print("$%2f was withdrawn, current balance is $%2f" %

(withdraw_amount, balance))

# User Input goes here, use if/else conditional statement to call function based on user input

userchoice = input("What would you like to do?\n")

if (userchoice == 'D'):

# here deposit function is called

deposit()

elif userchoice == 'W':

# here withdraw function is called

withdraw()

elif userchoice == 'B':

# here printbalance function is called

balance = printbalance()

print('{:.2f}'.format(balance))

else:

# it ends the program execution

sys.exit()


calculate the balance and withdrawal or should i say incoorporate it in to script.

Solutions

Expert Solution

There is already withdrawal and balance function to the script. There Does seem a problem with withdrawal function.

It is not printing float upto 2 decimal places. Assuming that is your problem. That is because in this printing statement of withdraw function

print("$%2f is greater than account balance $%2f\n" %

and

print("$%2f was withdrawn, current balance is $%2f" %

%2f is written instead of %.2f (there is a Dot(.) between % and 2)

that is why it is showing more that 2 decimal places. As for print balance function it's working fine although i made a little change

Here is the fixed program

And here are the desired outputs

------------------------------

Please rate if it helps :) Happy to help!


Related Solutions

/* Complete the TO DO comments below */ window.onload = function() { /* TODO add a...
/* Complete the TO DO comments below */ window.onload = function() { /* TODO add a border to the header of the page (a) a simple type selector, and (b) the style property of the element object. */ document.querySelector('TODO').TODO = TODO; /* TODO change the text of the h1 element by using (a) the first-child pseudo selector, and (b) the innerHTML property of the element object. */ document.querySelector('TODO').TODO = TODO; /* TODO change the background-color of the section with id...
Write a script that uses the function below to find root brackets for ?(?) = cos(ex)...
Write a script that uses the function below to find root brackets for ?(?) = cos(ex) + sin(?), between ? = 0 ??? ? = ? with ns=100. Plot the output by first plotting the function and then plotting ‘*’ at each bracket point (on the x-axis). You may either give the plot() function two sets of inputs, or you can use hold on ... hold off to add plots to your figure. function xb = incsearchv(func,xmin,xmax,ns)
7. Calculate the volume of 1 M solution of HCl that we need to add to...
7. Calculate the volume of 1 M solution of HCl that we need to add to 100mL of 0.1 M of phosphate buffer (0.1 M H3PO4 and 0.1 M Na2HPO4) to get pH =4. Is it a buffer and why?
I need a response for the statement below. Anything to add to the statement, corrections or...
I need a response for the statement below. Anything to add to the statement, corrections or questions about the statement? Eugenics, broken down, means good genes (Pence, 2017). There are positive and negative eugenics. Some contemporary developments in eugenics is “designer babies.” A designer baby is a baby whose genetic makeup has been designed prior to its birth to ensure desired characteristics or to prevent undesired ones (Pence, 2017). This reminds me of people wanting to have Olympic athletes as...
I need a response for the statement below. Anything to add to the statement, corrections or...
I need a response for the statement below. Anything to add to the statement, corrections or questions about the statement? The history of eugenics can be dated back to the 19th c (Wilson,2019). Eugenics is a practice that aids in filtering out good and bad genes in one's genetic makeup. Ideally, for some, this practice would focus primarily on ruling out disease processes rather than for aesthetics. However, sometimes in eugenics, it also includes the concept of trying to create...
Below is some code for a rectangle class that needs to be completed. Add member function...
Below is some code for a rectangle class that needs to be completed. Add member function declarations to the class declaration and member function definitions below the declaration. For the accessor functions, you can add the definitions directly into the class declaration. The goal is to code the class so that it works wthout changing the main program #include <iostream> using namespace std; // rectangle has a vertical height and horizontal width // The class below is a rectangle. It...
To model repayment of a loan, you need to calculate the interest on the balance and...
To model repayment of a loan, you need to calculate the interest on the balance and deduct any payments made. So if the balance at the start of the period is L the balance at the end of the period before the payment is L(1+r) where r is the interest rate per period (e.g. if the payments are monthly, it is a monthly interest rate) and the balance after the payment is L(1+r)−P where P is the payment per period...
I need to make 3 or 4-min video about the topic below. Just write script is...
I need to make 3 or 4-min video about the topic below. Just write script is fine. These are some considerations. Describe the new policy that you want Justify why your selection should be implemented with evidence and research Research possible policies This is kind of a persuasive presentation TOPIC: If you were implementing one new policy in Australia, with the aim of making the Australian population happier, what would it be and why?
Hi, I need the HTML5 code for the below. About Me **Would like to add a...
Hi, I need the HTML5 code for the below. About Me **Would like to add a image of a plane or something related to travel here. Mia Jo I am taking this class to earn my Computer programmer CL1. Things I Like to Do: Spend time with family Traveling People Watch Places I Want to Go or Have Visited: Dubai- December'18 Enjoyed shopping and the desert safari the most. Cuba- August '18 Enjoyed learning about the culture and history. China-...
USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one...
USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one vector v (either a column or a row) and outputs the same vector v of the same dimensions, but with the values in reverse order (use MATLAB function flip()). In other words, v will be overwritten by its flipped version. In your function, you may only use length() and floor(). You only need one loop. %this code tests the function, myflip, which you will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT