Type error: object takes no parameters


When I am trying to print my_account I get this error

my_account = BankAccount(“Matthew”)
Type error: object() takes no parameters

I have no clue of what it either means or how to fix it.
If someone could be kind enough to explain what the problem is I would be very grateful

This is the code that I have problems with

 class BankAccount(object):
  balance = 0
  def __init_(self, name):
    self.name = name
  def __repr__(self):
    return "This account belongs to %s. Your balance is $%.2f" % (self.name, self.balance)
  def show_balance(self):
    print "Your balance is %.2f$" % self.balance
  def deposit(self, amount):
    if self.amount <= 0:
      print "Your deposit amount is too low"
      print "Depositing %.2f to your account" % amount
      self.balance += amount
  def withdraw(self, amount):
    if amount > self.balance:
      print "Your withdrawal exceeds your balance"
      print "You are withdrawing %.2f$" % amount
      self.balance -= amount
my_account = BankAccount("name")
print my_account



the class doesn’t recognize the init method because you made a typo in the method name


omg hahahha thx man really appreciate it


because the init method wasn’t recognized, python as very surprised you gave an argument ("Matthew") when you initialized the class. Maybe you now also understand the error message better


yeah because without init() the object parameter wouldnt work?


yes, because the parameters are defined at the init method


Basically the object parameter is defined by init() parameters


yes, that is the magic part of __init__(), its the method that gets magically called when creating an instance of a class


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.