Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a below code and need to be corrected: ======================================= Check 1 failed Output: What would you like to do? How much would you

I have a below code and need to be corrected:

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

Check 1 failed

Output:

What would you like to do?

How much would you like to withdraw today?

Withdrawal amount was $100.00, current balance is 400.25

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?

How much would you like to withdraw today?

$700.00 is greater than account balance $500.25

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

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

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("How much would you like to withdraw today?"))

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

print("${} is greater than account balance ${} ".format(format(withdraw_amount,'.2f'), format(account_balance,'.2f'))) # if yes then

else:

balance = account_balance - withdraw_amount

print("Withdrawal amount was ${}, current balance is {}".format(format(withdraw_amount,'.2f'), format(balance,'.2f')))

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

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

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Get married, do not wait for me

Answered: 1 week ago

Question

10. What is meant by a feed rate?

Answered: 1 week ago

Question

Describe the five elements of the listening process.

Answered: 1 week ago