Question

In: Computer Science

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

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
  1. The opening balance has been assigned to a variable called account_balance equal to $500.25. Notice the use of the 'float' method in order to ensure that 'account_balance' is a float value.
  2. Request the action to be taken on the account.
  3. Write a print balance function that returns the account balance.
  4. Create the action for selection ‘B’, Account Balance, to call the print balance function then print the account balance once the value is returned from the function.
  5. Test your 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 : %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()

Solutions

Expert Solution

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


Related Solutions

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 Write a function called `deposit`. Request from the user the amount to be deposited. This value should...
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...
In C++ Instructions: Use a void function to print the following message (should be in welcome...
In C++ Instructions: Use a void function to print the following message (should be in welcome function) Welcome to the Event Scheduling program create 3 int arrays with 3 positions (one array for days one array for moths and one array for years) (should be in main) Create a file that contains the following (you can just create the file or write the file in the program) 1 / 26 / 2021 12 / 13 / 2020 2 / 1...
Instructions (in C++): 1 ) Use a void function to print the following message (should be...
Instructions (in C++): 1 ) Use a void function to print the following message (should be in welcome function) Welcome to the Event Scheduling program 2 ) create 3 int arrays with 3 positions (one array for days one array for moths and one array for years) (should be in main) 3 ) Create a file that contains the following (you can just create the file or write the file in the program) 1 / 26 / 2021 12 /...
(True or False) The following function will compile. void print(int num) { return num+1; } Group...
(True or False) The following function will compile. void print(int num) { return num+1; } Group of answer choices True False Flag this Question Question 2 10 pts (True or False) The following code will output "I was true". bool isGreater(string s1, string s2) { if(s1 > s2) { return true; } return false; } int main() { if(isGreater("before","back")) { cout << "I was true"; } else { cout << "I was false"; } return 0; } Group of answer...
Write a C++ program to multiply two matrices a and b and print the result. Use...
Write a C++ program to multiply two matrices a and b and print the result. Use two-dimensional arrays to represent the matrices.
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
Write a function hitRate(A, B) to return the percentage of elements in array A that match...
Write a function hitRate(A, B) to return the percentage of elements in array A that match the elements with the same index in array B. A and B are 1darrays or 2darrays of the same shape. Sample: if X = np.array([1, 3, 5, 8]); Y = np.array([2, 1, 3, 8]), then hitRate(X, Y) returns 0.25. in python program
Please, use C++ for this question. (b) Write the definition of displayBox() function. The function will...
Please, use C++ for this question. (b) Write the definition of displayBox() function. The function will display a matrix of integers from 1 to 4 such that the first row will contain four 1s, the second row will contain four 2s, the third row will contain four 3s and the fourth row will contain four 4s. Function must use nested loops to display each column and row heading as well as the numbers. The function has no parameters and no...
Use the exchange return function between the Euro and the US dollar and the domestic money...
Use the exchange return function between the Euro and the US dollar and the domestic money demand and money supply functions to trace the consequences of (a) an increase in the real money supply, and (b) a decrease in the real money supply. Carefully identify all the steps for each case beginning with equilibrium values for current exchange rate of the Euro in dollars, the expected exchange rate of the Euro in dollars one year from today, the current price...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT