Question

In: Computer Science

Deposit function. Calculate the Balance - Deposit If the action is Deposit 'D’, use a deposit...

Deposit function.

Calculate the Balance - Deposit

If the action is Deposit 'D’, use a deposit function to add funds to the account

Deposit Input

userchoice = input ("What would you like to do?\n")
userchoice = 'B'
deposit_amount = 200

Deposit Output

What would you like to do?
How much would you like to deposit today?
Deposit was $200, current balance is $700.25
  1. Write a function called `deposit`.
  2. Request from the user the amount to be deposited. This value should be stored in a variable called `deposit_amount`. Use both the `input` and `float` methods in order to ensure the `deposit_amount` is a float value.
  3. Calculate a new account balance.
  4. The calculation for depositing funds into the account is `account_balance = account_balance + deposit_amount`.
  5. Print the new account balance.

#import sys #no need for this module

#account balance

account_balance = float(500.25)

#<--------functions go here-------------------->

#printbalance function

def printbalance():

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

#deposit function

def deposit():

#accessing account_balance variable which is outside the function

global account_balance

deposit_amount=float(input('How much would you like to deposit today?'))

account_balance+=deposit_amount

print('Deposit was $%.2f, current balance is $%.2f' % (deposit_amount,account_balance))

#withdraw function

def withdraw():

#accessing account_balance variable which is outside the function

global account_balance

withdrawal_amount=float(input('How much would you like to withdraw?'))

#withdrawing only if there is enough balance

if account_balance

print('withdrawal_amount is greater that your account balance of $%.2f' % account_balance)

else:

account_balance-=withdrawal_amount

print('Withdrawal amount was $%.2f, current balance is $%.2f' % (withdrawal_amount,account_balance))

userchoice=''

#looping until user enters Q or q

while userchoice.upper()!='Q':

userchoice = input ("What would you like to do? (D/W/B or Q)\n")

#converting to upper case to reduce comparisons

userchoice=userchoice.upper()

#performing operations based on choice

if userchoice=='D':

deposit()

elif userchoice=='W':

withdraw()

elif userchoice=='B':

printbalance()

elif userchoice=='Q':

print('Thank you for banking with us.')
  
else:

print('Not a valid choice')

Solutions

Expert Solution

For the above program, we need to have the following things into consideration.

  1. We need to subtract the amount which is withdrawn.
  2. Then we need to print the output.

Following is the code for the same.

def printbalance():
    print("Account balance: $%.2f" % account_balance)
# deposit function
def deposit():
    # accessing account_balance variable which is outside the function
    global account_balance
    deposit_amount = float(input('How much would you like to deposit today?'))
    account_balance += deposit_amount
    print('Deposit was $%.2f, current balance is $%.2f' % (deposit_amount, account_balance))
# withdraw function
def withdraw():
    # accessing account_balance variable which is outside the function
    global account_balance
    withdrawal_amount = float(input('How much would you like to withdraw?'))
    # withdrawing only if there is enough balance
    if account_balance < withdrawal_amount:
        print('withdrawal_amount is greater that your account balance of $%.2f' % account_balance)
    else:
        account_balance -= withdrawal_amount
    print('Withdrawal amount was $%.2f, current balance is $%.2f' % (withdrawal_amount, account_balance))
userchoice = ''
account_balance = 0
# looping until user enters Q or q
while userchoice.upper() != 'Q':
    userchoice = input("What would you like to do? (D/W/B or Q)\n")
    # converting to upper case to reduce comparisons
    userchoice = userchoice.upper()
    # performing operations based on choice
    if userchoice == 'D':
        deposit()
    elif userchoice == 'W':
        withdraw()
    elif userchoice == 'B':
        printbalance()
    elif userchoice == 'Q':
        print('Thank you for banking with us.')
    else:
        print('Not a valid choice')

Following is the snippet of the above code.

Following is the sample output.

That was a nice question to answer
Friend, If you have any doubts in understanding do let me know in the comment section. I will be happy to help you further.
Please like if you think effort deserves like.
Thanks


Related Solutions

This is in python3.. Calculate the Balance - Deposit If the action is Deposit 'D’, use...
This is in python3.. Calculate the Balance - Deposit If the action is Deposit 'D’, use a deposit function to add funds to the account Deposit Input userchoice = input ("What would you like to do?\n") userchoice = 'B' deposit_amount = 200 Deposit Output What would you like to do? How much would you like to deposit today? Deposit was $200, current balance is $700.25 Customer Deposit Write a function called `deposit`. Request from the user the amount to be...
If the action is Balance 'B’, use a print balance function to return and print an...
If the action is Balance 'B’, use a print balance function to return and print an account balance. You will need to write a function called printbalance. a. Create a prompt for the user to input the account action. There are three possible actions: Code Action Function D Deposit deposit_amount W Withdrawal withdrawal_amount B Account Balance account_balance Create a function to print the account_balance, print the account actions and create the action for outputting the account balance outputting. Input Information...
Describe the purpose, history, function, structure, and use in action of the National Incident Management System
Describe the purpose, history, function, structure, and use in action of the National Incident Management System
Explain the mode of action of anti D prophylaxis in a D negative mother ? (300...
Explain the mode of action of anti D prophylaxis in a D negative mother ? (300 words max)
use C++ to create a function to calculate it. My requirements are very simple: function should...
use C++ to create a function to calculate it. My requirements are very simple: function should be general to deal with any size matrices. That's all.
you will be assessed on the use of BINOM.DIST function, and creating formula to calculate the...
you will be assessed on the use of BINOM.DIST function, and creating formula to calculate the expected value of a binomial distribution. You will also be asked to interpret a probability value. Multiple Choice Test Chris is sitting a multiple choice test in statistics. The test consists of 9 items and each item has 5 options. After the test, Chris told you he didn’t study for the test at all and guessed all answers. a) If Chris guessed each and...
The Bank Statement Balance is $10,000. The Book Balance is $12,000. The is a Deposit in...
The Bank Statement Balance is $10,000. The Book Balance is $12,000. The is a Deposit in Transit of $2000. There is an Outstanding Check of $1000. There is an NSF Check from a customer of $1000. Based on this data, complete a bank reconciliation
matlab use matlab to calculate the velocity of the vertical falling ball (v) as a function...
matlab use matlab to calculate the velocity of the vertical falling ball (v) as a function of time by numerical derive the following measurement values.(x is height in meters and y is the landing time in milliseconds) Make sure that the speed in the starting point is 0. Then reset instantaneous velocity as a function of time in a diagram with matlab x=[0.00 0.20 0.40 0.60 0.80 1.00 1.20 1.50 2.00 2.50 3.00 3.40 3.80 4.20 4.60 5.0] y=[[0.00 1.620...
How to use the COUNTIFS Function in Excel. Need to calculate the number of days. Independent...
How to use the COUNTIFS Function in Excel. Need to calculate the number of days. Independent Challenge 4. #g page 127 Microsoft Excel 2016 Comprehensive
1. Use excel function exp( ) to calculate raising e to the power of (-2.5 +...
1. Use excel function exp( ) to calculate raising e to the power of (-2.5 + 2*X1 + 3*X2), where X1=5.6 and X2=3. 2. Denote the result from part 1 as Y, calculate the Y/(1+Y), and let us denote this ratio as prob, i.e., prob= Y/(1+Y). Demonstrate the quantity is sandwiched by this interval (0, 1) by trying different values of X1 and X2. Also realize the any quantity that is capped between 0 and 1 can lend itself to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT