Python Forum
whats wrong with my code? syntax errors - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: whats wrong with my code? syntax errors (/thread-2437.html)



whats wrong with my code? syntax errors - r6lay - Mar-16-2017

stimulate an atm machine. (Game: ATM machine) Use the Account class created in Exercise 7.3 to simulate an ATM machine. Create ten accounts in a list with the ids: 0, 1..., 9, and an initial balance of $100.00. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can enter a choice of 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money, and 4 for exiting the main menu. Once you exit, the system will prompt for an id again. So, once the system starts, it won't stop.

so this is my code and I'm getting a syntax error


class Account:
    def _init_(self, dateCreated,bank_id = 0, balance = 0.0, annualInterestRate = 0,0): <- I get a syntax error here
        self.bank_id = bank_id
        self.balance = balance
        self.annualInterestRate = annualInterestRate
        self.dateCreated = dateCreated
    
    def createAccount(self):
        Account('00-00-0000', 0, 0.0, 0.0)
        print("Default account instance is created")
    
    def createAccountwithvals(self, spec_id, ini_bal):
        Account(self.dateCreated, spec_id, ini_bal, self.annualInterestRate)
        print("Account is created with id " + str(spec_id) + " and with a balance of " + str(ini_bal))
    
    
    def getid(self):
        return self.bank_id
    def setid(self,val):
        self.bank)id = val
    
    
    def getbalance(self):
        return self.balance
    def setbalance(self, val):
        self.balance = val
        
    def getannualInterestRate(self):
        return self.annualInterestRate
    def setannualInterestRate(self,val):
        self.annualInterestRate = val
    
    def getdateCreated(self):
        return self.dateCreated
    
    def getMonthlyInterestRate(self):
        return (self.annualInterestRate/12)
    
    def withdraw(self, val):
        print("balance before withdrawl", self.balance)
        self.balance= self.balance - val
        print("balance after withdrawl", self.balance)
    
    def deposit(self, val):
        print("Balance before deposit", self.balance)
        self.balance = self.balance + val
        print("Balance after deposity", self.balance)

if __name__ == '__main__':
    x = Account('3-2-2017', 1122, 20000, 4.5)
    x.withdraw(2500)
    x.deposit(3000)
    x.createAccountwithvals(2222, 15000)



RE: whats wrong with my code? syntax errors - Larz60+ - Mar-16-2017

stimulate an atm machine How exciting for the machine ... I think you meant simulate!


RE: whats wrong with my code? syntax errors - r6lay - Mar-16-2017

(Mar-16-2017, 03:36 PM)Larz60+ Wrote: stimulate an atm machine How exciting for the machine ... I think you meant simulate!

hahaha whoops


RE: whats wrong with my code? syntax errors - micseydel - Mar-16-2017

When I'm trying to solve a problem like this for myself, I try to simplify the problem. Your code can easily be reduced to the following and still reproduce the issue
class Account:
    def _init_(self, dateCreated,bank_id = 0, balance = 0.0, annualInterestRate = 0,0):
        pass
We can do more as well, such as make it a function rather than a class
def f(self, dateCreated,bank_id = 0, balance = 0.0, annualInterestRate = 0,0):
    pass
and if we're persistent, and try different things, we can get it down to this
def f(annualInterestRate = 0,0):
    pass
or maybe even more. Can you see what's wrong with this? And if not, could you elaborate on what you intended?


RE: whats wrong with my code? syntax errors - wavic - Mar-16-2017

It is __init__() - with double underline


RE: whats wrong with my code? syntax errors - micseydel - Mar-16-2017

@wavic: that's a different issue, but also definitely worth noting :)