Python Forum

Full Version: Help with multiple conditions on ATM program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am new to python and decided to see if I could create an ATM program I called a JTM as a joke but anyway I have it working well I just want to make it so when you want to withdraw an amount that will make your balance < 0 you won't be able to. So as long as balance > 0 you can withdraw otherwise you get a message saying you are unable to withdraw check balance, and then loop back to the beginning.

There are some basic things wrong here.
Calling another is not necessary and annoying:
balance = 0
withdraw = 0
option = 0
deposite = 0
import sys

print("Welcome to the JTM")
input("Press ENTER to continue")


def another():
    answer = input("Would you like to make another transaction y/n?: ").lower()
    if answer == 'y':
        active = True
    else:
        active = False
        sys.exit("Thank you for using JTM")


active = True

while active:
    print("1: Deposit")
    print("2: Withdraw")
    print("3: Balance")
    print("4: Quit")

    option = int(input("What would you like to do: "))

    if option == 1:
        deposite = int(input("How much would you like to deposit: "))
        print("Your deposited $" + str(deposite))
        balance = balance + deposite
    elif option == 2:
        print("Your total amount available for withdrawal is: $" + str(balance))
        while True:
            withdraw = int(input("Withdraw: $"))
            if withdraw > balance:
                print("Cannot withdraw more than available balance")
                continue
            balance = balance - withdraw
            break
    elif option == 3:
        print("balance: $" + str(balance))
    elif option == 4:
        sys.exit("Thanks")
Okay well, I am open to any advice anyone can provide, what would be a smarter way to do this? I honestly thought that was the best way to do it but then again I am new to this, rip my code apart if you want to tell me everything that's wrong with it or anything I can change but also do you know how to answer my original question?
I provided it. see the listing in my post
Oh okay I see what you mean I might as well just delete the entire function then. How would I make a message come up if you try to withdraw more than the total you have.
It's there!
if withdraw > balance:
                print("Cannot withdraw more than available balance")
                continue
Oh wow haha I missed that...I thought it would be way harder but okay.