In: Computer Science
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
The following data will be used as input in the test:
userchoice = input ("What would you like to do?")
userchoice = 'B'
Output Information
Your current balance: 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 : %2f" % account_balance)
#the function for deposit
#This is a custom function
def deposit():
deposit_amount = float(input("Enter amount to deposit : ")) # takes
in input for deposit amount
balance = account_balance + deposit_amount #calculates
balance
print("Deposit was $%2f, current balance is $%2f" %(deposit_am
ount,balance)) # prints out the balance
#function for withdraw
#this is a custom function
def withdraw():
withdraw_amount = float(input("Enter amount to withdraw")) # takes
in the withdraw amount
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
print wd amount greater than balance
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
printbalance()
else:
# it ends the program execution
sys.exit()
Thanks for the question, 
==============================================================================
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():
    deposit_amount = float(input("Enter amount to deposit : ")) # takes in input for deposit amount
    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():
    withdraw_amount = float(input("Enter amount to withdraw")) # takes in the withdraw amount
    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()

