Answer to Question #160135 in Python for Meera

Question #160135

#Write a program that simulates using a bank machine. I have listed five 5 functions that should be called in the main program that you have to complete. I also have taken the liberty of starting the skeleton code for you. You need to write the code for each functions and then create the main code that will call for these functions. (Perhaps the program should run in the while True loop as I have started for your at the bottom).



def getDepositeAmount():

#should handle getting input from the user. Make sure your value is an int or float.

return #deposit amount




def deposit(depositAmount, accountBalance):

#should add the deposit to the account balance


return #the new account balance



def getWithdrawalAmount(accountBalance):

#should handle getting input from the user and evaluate if the withdraw amount is less than the account balance. This function should continue to loop until the value of the withdrawal is less than or equal to the accountBalance


return #The function should return the withdrawl value



def withdraw(withdrawlAmount, accountBalance):

#should subtract the withdrawl amount from the account balance


return #return the new account balance



def printBalance(accountBalance):

#should print out the current account balance in a nicely formatted way. Maybe ...

#*****************************************

#Your account balance is: $1090.89

#*****************************************


return



#You need to start with an account balance, feel free to make yourself a billionaire if you like. Right now I have set it to default $0.00

acountBalance = 0.00



while True:

#main program should run here. Feel free to edit to change the code here. This is just a demo.

userChoice = int(input('Welcome to your bank. Please pick one of the following options....\n1. Deposit\n2. Withdrawal\n3. Account balance\n4. Exit bank\nEnter your choice [1,2,3,4]:'))





1
Expert's answer
2021-02-01T03:31:58-0500
account = 0
def getDepositAmount():
    depositAmount = int(input("Enter amount you want to deposit:"))
    return depositAmount
def deposit(depositAmount):
    global account
    account += depositAmount
    print(depositAmount,"has been added to your account")
    return account
def getWithdrawalAmount():
    global account
    withdrawalAmount = 0
    while True:
        try:
            withdrawalAmount = int(input("Enter amount you want to withdraw:"))
            if withdrawalAmount <= account :
                break
            print("Invalid input,Try again")
        except Exception as e:
            print(e)
            break
    return withdrawalAmount
def withdraw(withdrawalAmount):
    global account
    account -= withdrawalAmount
    print(withdrawalAmount,"has been removed from your account")
    return account
def printBalance():
    global account
    print(account)
    return
def main():
    userChoice = ""
    while userChoice != "d":
        print("Welcome to your bank.Please pick one of the following options.\na. Deposit\nb. Withdrawal\nc.Check account balance.\nd. Exit bank.")
        userChoice = input("Enter your choice:")
        if userChoice == "a":
            deposit(getDepositAmount())
        elif userChoice == "b":
            withdraw(getWithdrawalAmount())
        elif userChoice == "c":
            printBalance()
        elif userChoice == "d":
            print("Goodbye")
        else:
            print("Invalid input")

if __name__=="__main__":
    main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS