Question: I have below code! Would anyone help me to fix the code? Python 3.6 ============================== Q: Calculate the Balance - Withdrawal If the action is

I have below code! Would anyone help me to fix the code?

Python 3.6

==============================

Q: 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? ") 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 
  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

===================

Error message:

 

Check 1 failed

Output:

What would you like to do?

Enter amount to withdraw$100.000000 was withdrawn, current balance is $400.250000

Expected:

What would you like to do?

How much would you like to withdraw today?

Withdrawal amount was $100.00, current balance is $400.25

Check 2 failed

Output:

What would you like to do?

Enter amount to withdraw$700.000000 is greater than account balance $500.250000

Expected:

What would you like to do?

How much would you like to withdraw today?

$700.00 is greater than your account balance of $500.25

======================

My code

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? "))

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 " %

(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? ")

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()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!