Python Forum
whats wrong with my code? syntax errors
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
whats wrong with my code? syntax errors
#1
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)
Reply
#2
stimulate an atm machine How exciting for the machine ... I think you meant simulate!
Reply
#3
(Mar-16-2017, 03:36 PM)Larz60+ Wrote: stimulate an atm machine How exciting for the machine ... I think you meant simulate!

hahaha whoops
Reply
#4
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?
Reply
#5
It is __init__() - with double underline
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
@wavic: that's a different issue, but also definitely worth noting :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] new to python hello world code gives errors giobastidas1970 1 1,446 Mar-11-2023, 12:48 PM
Last Post: jefsummers
  im not sure what ive done wrong code doesnt run dgizzly 3 1,357 Nov-16-2022, 03:02 AM
Last Post: deanhystad
  what is wrong with my code 53535 4 1,529 Apr-07-2022, 11:37 AM
Last Post: 53535
  What's wrong with my code? NeedHelpPython 4 2,207 Oct-22-2021, 07:59 PM
Last Post: Yoriz
  urgent I got a syntax errors alm 2 5,840 Feb-28-2021, 02:54 PM
Last Post: alm
  Help with my code due 11:59 pm, can you tell me where I went wrong and help fix it? shirleylam852 1 2,656 Dec-09-2020, 06:37 AM
Last Post: stranac
  I am getting an incorrect average, and not sure why? What's wrong with my code? shirleylam852 8 4,679 Nov-20-2020, 05:32 AM
Last Post: deanhystad
  I'm getting a syntax error very early on in my code and I can't quite figure it out. liloliveoil 1 1,997 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Whats the difference between these two? Puxk 4 3,394 Jul-08-2020, 06:02 PM
Last Post: stullis
  Something is Wrong with my code susmith552 4 3,032 Nov-28-2019, 02:16 AM
Last Post: susmith552

Forum Jump:

User Panel Messages

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