user5374923 user5374923 - 1 year ago 123
Python Question

Python: setting max for bank withdraw

I'm new to python and I am still trying to get the hang of it. I'm attempting to change the processing function in the following code so that the user can not withdraw more money then what the "bank" has on record, which is 500. I was hoping that someone could help. Would I enter an if statement for >500?

#Simple Bank Atm
def main():

#Input Function
def getInput(pin):
pin=int(input(“Please enter your PIN:”))
return pin

#Processing Function
def processing(pin,PIN,balance,success):
if pin==PIN:
amt=float(input(“How much would you like to withdraw?”))
return pin,PIN,balance,success
return pin,PIN,balance,success

Answer Source

You can use an if condition to do this.

if amt <= balance: #Can't withdraw over your current balance
    balance -= amt
    print("Error. Amount exceeds funds on record.")

Also, other things aside you're returning the same thing inside your if and else condition and if this is what you really want to return it's redundant to have it in both. You can just have it after your else statement at the same indentation level

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download