Python Forum
Help with multiple conditions on ATM program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with multiple conditions on ATM program
#1
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.

Reply
#2
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")
Reply
#3
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?
Reply
#4
I provided it. see the listing in my post
Reply
#5
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.
Reply
#6
It's there!
if withdraw > balance:
                print("Cannot withdraw more than available balance")
                continue
Reply
#7
Oh wow haha I missed that...I thought it would be way harder but okay.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 3 747 Aug-09-2023, 05:51 PM
Last Post: Calab
  How do you format Update statement with multiple conditions hammer 4 2,098 Dec-16-2021, 10:49 PM
Last Post: hammer
  Multiple conditions when indexing an array with or without np.where noob2305 1 2,669 Oct-25-2020, 02:06 PM
Last Post: jefsummers
  Multiple conditions, one is null moralear27 1 2,200 Sep-13-2020, 06:11 AM
Last Post: scidam
  multiple conditions Chandan 7 4,002 Jan-31-2020, 12:53 AM
Last Post: Chandan
  Having issues getting a multiple choice test program to work Py_JohnS 2 3,482 Sep-01-2018, 11:06 PM
Last Post: Py_JohnS
  Simplifying multiple "or" conditions in if statement. rhubarbpieguy 8 102,114 Jul-22-2017, 12:19 PM
Last Post: rhubarbpieguy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020