How to call the superclass in this ATM machine game with Python?

atm program in python
atm program in python using class

I am trying to create an ATM game that uses a list of 10 accounts (from 0-9) and all are set to 100 to start. I have all the loops and menu items set up as needed in the main() function, but I think my Account Class is not set up right because when I pass arguments to the class functions I get errors. Is there a way I should be initiating an empty list in the Class to start? Or is there a different mistake I made in the main() function?

Here is the error I get when choosing menu item 1 to get the balance:

  File "/Users/Beadog/PycharmProjects/M08_12.3/gameATMMachine.py", line 82, in getBalance
    return format(self.__balance, ".2f")
AttributeError: 'int' object has no attribute '_Account__balance'

And here is the full code:

class Account:
    def __init__(self, id = 0, balance = 100):
        self.__id = id
        self.__balance = balance

    def getId(self):
        return self.__id

    def getBalance(self):
        return format(self.__balance, ".2f")

    def setID(self, id):
        self.__id = id

    def setBalance(self, balance):
        self.__balance = balance

    def withdrawal(self, withdrawalAmount):
        if withdrawalAmount < self.__balance:
            self.__balance -= withdrawalAmount
        else:
            print("Insuficient Funds.")

    def deposit(self, depositAmount):
        self.__balance += depositAmount


def main():
    accounts = []
    for i in range(10):
        accounts.append(Account(i, 100))

    while True:
        id = eval(input("Enter account ID: "))

        if id >= 0 and id <= 9:

            print()
            print("Main menu")
            print("1: check balance")
            print("2: withdraw")
            print("3: deposit")
            print("4: exit")
            print()

            menuChoice = eval(input("Enter a choice: "))
            print()

            while menuChoice != 4:
                if menuChoice == 1:
                    balance = Account.getBalance(id)
                    print("The balance is ", balance)
                    print()
                    print("Main menu")
                    print("1: check balance")
                    print("2: withdraw")
                    print("3: deposit")
                    print("4: exit")
                    print()
                    menuChoice = eval(input("Enter a choice: "))
                    print()

                elif menuChoice == 2:
                    withdrawalAmount = eval(input("Enter withdrawal amount: "))
                    Account.withdrawal(id, withdrawalAmount)
                    print()
                    print("Main menu")
                    print("1: check balance")
                    print("2: withdraw")
                    print("3: deposit")
                    print("4: exit")
                    print()
                    menuChoice = eval(input("Enter a choice: "))
                    print()
                elif menuChoice == 3:
                    depositAmount = eval(input("Enter deposit amount: "))
                    Account.deposit(id, depositAmount)
                    print()
                    print("Main menu")
                    print("1: check balance")
                    print("2: withdraw")
                    print("3: deposit")
                    print("4: exit")
                    print()
                    menuChoice = eval(input("Enter a choice: "))
                    print()
                else:
                    menuChoice = eval(input(("Please enter a valid menu choice (1-4): ")))
                    print()
        else:
            print("Account ID must be a number between 0 and 9. Please try again.")
            print()

main()

Don't know how to approach this: Simulating an ATM Machine, I have to define a subclass (in the test program) to a superclass (the account class) (Game: ATM machine) Use the Account class to simulate an ATM machine. Unfortunately I've never found a good introduction to statistics with Python (there are self.name = name self.age = age def sit(self): '''We're calling a instance  super () returns a delegate object to a parent class, so you call the method you want directly on it: super ().area (). Not only does this save us from having to rewrite the area calculations, but it also allows us to change the internal .area () logic in a single location. This is especially in handy when you have a number of subclasses

The problem is that you are not referring to an Account instance when you call getBalance() and other methods, you are referring to the Account class itself. You retrieve the Account instance by getting it from the array where you stored it, not by passing an id to the Account method itself.

Instead of this:

balance = Account.getBalance(id)

You should be doing things like this:

account = accounts[id]
balance = account.getBalance()

Replace things like this:

Account.withdrawal(id, withdrawalAmount)

With this

account = accounts[id]
account.withdrawal(withdrawalAmount)

And so on. You were correct in the way you created and stored the Account instances, you just have to refer to them correctly.

Python program to create Bankaccount class with deposit, withdraw , It is run as soon as an object of a class is instantiated. declaring that balance is 0 using self argument then we simply print a statement welcoming to Machine. In this Python tutorial, learn the basic, common functions when using an ATM machine. This Python tutorial will give a basic overview on creating a class with methods and objects while implementing loops such as while loops and for loops, and if statements. Note: This Python tutorial is implemented in Python IDLE (Python GUI) version 3.7.

You have two errors errors in your code. First notice that you are creating a list of accounts with:

accounts = []
for i in range(10):
    accounts.append(Account(i, 100))

but, then, you are not using it. Instead, you are calling the Accounts method using the class name Account instead of the the variable accounts[i] which holds a reference to an istance of the class Account:

balance = Account.getBalance(id)

To make you code work, you need to change the previous line in:

balance = accounts[id].getBalance()

Notice that I removed the id argument from the getBalance() function call (your second error). In fact, your definition of this method does not require any argument (except the one referring to the object it belong to: self):

def getBalance(self):
    return format(self.__balance, ".2f")

StateMachine, Each State subclass defines its run( ) behavior, and also establishes its next StateMachine/mousetrap1/MouseTrapTest.py # State Machine pattern using 'if'  Create an ATM Program that asks a user for their name and pin; Program will loop through asking user if they want to check balance, withdraw, deposit, or exit. You exit the loop when user selects exit. The initial balance is $10,000; Create a text file that records all transactions. First 2 lines of the file should be the User's name and Pin

I'm curious. Can u set the code correctly pls?

Cracking Python Bootcamp – Nextjournal, ATM Machine. California Lottery. The Dice Remix of Python Template by Nextjournal pass. Python. Infinite loops have their place e.g. can be used to prompt user input in simple games. To run tests from modules, classes, or individual methods: xxxxxxxxxx super().__init__() # calls the superclass constructor ​ The main thing I would say here is that you have 2 nigh identical functions apart from the balance being passed to them. Instead of checking_account and savings_account being different functions, make a single account_interaction function that takes an argument which you can then pass to the choden function.

Bank account program in python using inheritance, In this lab, you will create a base class, called CBankAccount, and two additional classes Zap and Zoom game; Python program to convert temperature from Celsius to Fahrenheit and Mar 15, 2019 · Python ATM Program Output. When it comes to data manipulation and machine learning using Python, it is generally  super() function in Python: Python super function provides us the facility to refer to the parent class explicitly. It is basically useful where we have to call superclass functions. It returns the proxy object that allows us to refer parent class by ‘super’. To understand Python super function we must know about the inheritance. In Python

Simple bank account program in python, It will run on any platform that can run Python and wxPython. Aug 20, 2013 · Python Hangman Game Python Command Line IMDB Scraper Python code but what about creating a subclass which inherits properties of class BankAccount with the Cash Withdrawal Machine, uses a computer program to interact DISPLAY  The super () builtin returns a proxy object (temporary object of the superclass) that allows us to access methods of the base class. In Python, super () has two major use cases: Allows us to avoid using the base class name explicitly. Working with Multiple Inheritance. Example 1: super () with Single Inheritance.

Bank account program in python using class, Game of Life: Create a class for the Game of Life and then build the game around it. A 30000 >>> Tags: python,python programming,atm machine program in of its base class or classes, and a method can call the method of a base class  Subclass in Python By the name of the topic, it is clear in itself that we are going to deal with subclasses of any class. To give you a general idea, think that square is also a rectangle, which means that it is a subclass of rectangle.

Comments
  • question edited to include error
  • thank you SO MUCH! You all have been so incredibly helpful on here and I hope to have the knowledge and experience to pay it forward someday soon!
  • Thank you very much! The prior answer did it a little differently: accounts[id].withdrawal(withdrawalAmount) I see both ways work!
  • Glad to help! Yes they are only stylistically different. I like to do things in a more step-by-step way just to make them more explicit, whereas the prior answer does everything in one line. In most code, you are probably more likely to see it the way the prior answer did it than the way I did it. The only reason to do it my way besides illustrating things would be if you wanted to do something with the Account instance after calling withdrawal on it. Then it might make sense to store it in a variable like I did (the account variable), rather than writing accounts[id] again.
  • Hi - just the single lines of code in the 3 menu choices needed changed. So menuChoice 1 was changed to: balance = accounts[id].getBalance() and menuChoice 2 was changed to: accounts[id].withdrawal(withdrawalAmount) menuChoice 3 was changed to: accounts[id].deposit(depositAmount)
  • Hi, your code still not working perfectly. Cause when I choose "exist " it still looping the main menu
  • it is supposed to ask you for a new account ID if you choose option 4. option 4 will kick you out of the inner while loop and put you back into the outer while loop which is set to always run unless you kill the program.