Question: The challenge is to write a basic ATM script for Python. Need to execute simple functions like display a balance, withdraw and deposit and then

The challenge is to write a basic ATM script for Python. Need to execute simple functions like display a balance, withdraw and deposit and then finally close out the program saying what the ending balance is. I feel like I am close to what I'm looking for. However, my script does not update as it progresses. It doesn't close out until it's supposed to, but if I have it perform a withdrawal and then a deposit, it does it on the original amount rather than the new amount after the previous function. Want to correct it so that it will account for previous actions. The following is my script. If anyone has any suggestions on how to fix it, and if you don't mind, an explanation as well. This will be my only scripting class but I'm trying to learn the material and would like to continue after. Any help is really appreciated. Thank you.

import sys

# account balance account_balance = float(500.25)

#Function will output the balance in the account. This is also a custom or #user-defined funtion def printbalance(): print("Your current balance : %.2f" % account_balance)

#Functino that takes user input and will output the new balance. This is #also a custom or user defined function. def deposit(): deposit_amount = float(input("Enter amount to deposit : ")) balance = account_balance + deposit_amount print("Deposit was $%.2f, current balance is $%.2f" %(deposit_amount,balance))

#Function that takes user input and output the new balance. This is also a custom or #user defined function def withdraw(): withdraw_amount = float(input("Enter amount to withdraw : ")) if(withdraw_amount > account_balance): print("$%.2f is greater than account balance $%.2f " %(withdraw_amount,account_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 while(1): userchoice = input("What would you like to do? ") if (userchoice == 'D'): deposit() elif userchoice == 'W': withdraw() elif userchoice == 'B': printbalance() else: print("Thank You for banking with us. ") sys.exit()

The challenge is to write a basic ATM script for Python. Need

to execute simple functions like display a balance, withdraw and deposit and

4 import sys 6 7 # account balance account_balancefloat (500.25) 9 10 #Function will output the balance in the account. This is also a custom or #user-defined funtion 12def printbalance) 13 14 15 16 17 def deposit): 18 19 print ("Your current balance : %.2f" % account-balance) #Functi no that takes user input and will output the new balance. This is also a custom or user defined function. deposit_amount float (input("Enter amount to deposit)) balanceaccount_balance + deposit_amount print ("Deposit was $% .2 f, current balance is $%.2f" %(deposit-amount ,balance)) 21 #Function that takes user input and output the new balance. This is also a custom or #user defined function 23 24 def withdraw) 25 26 27 28 29 30 31 32 33 while(1): 34 35 36 37 38 39 40 41 withdraw_amountfloat (input("Enter amount to withdraw")) if (withdraw_amount> account balance): print("$%,2t is greater than account balance $%.2f " %(withdraw. amount , account-balance)) else: balance = account-balance - print ("$%.2f was withdrawn, withdraw-amount cu rrent balance balance)! s $%.2f" % (withdraw-amount, #User Input goes here, use if/else conditional statement to call function based on user input userchoiceinput("What would you like to do? ") if (userchoiceD') elif userchoice W elif userchoice B else deposit() withdraw() printbalance)

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!