Bank Account project error


#1

So I wrote this code, but I get an error message:


class BankAccount(object):
  balance = 0.0
  def __init__(self, name):
    self.name = name
    
  def __repr__(self):
    return "This account belongs to Mr/Ms %s and the balance is $%s" % (self.name, self.balance)
  def show_balance(self):
    print "Your current balance is $%s" % (self.balance)
    
  def deposit (self, amount):
    if amount <= 0:
      print "More than zero, please."
      return
    else:
      print "You deposit $%" % (self.amount)
      self.balance += amount
      self.show_balance()
      
    def withdraw(self, amount):
      if amount > self.balance:
        print "Dude, you dont have that much money."
        return
      else:
        print "Withdraw amount is $%s.2f" % (self.amount)
        self.balance -= sef.amount
        self.show_balance()
        
my_account = BankAccount("Octavius Maximus")
print my_account
my_account.show_balance()
my_account.deposit(2000)
my_account.withdraw(1000)
print my_account


        
        
  I assume that the deposit amount does not pass down to the deposit function, but I cant see how I could fix that.

I hope you can help :slight_smile:


#2

this is the message i get

Traceback (most recent call last):
File "bankaccount.py", line 36, in
my_account.deposit(2000)
File "bankaccount.py", line 18, in deposit
print "You deposit $%" % (self.amount)
AttributeError: 'BankAccount' object has no attribute '
amount


#3

Do you mean that self should have an attribute named amount? If so, where did you add that attribute to your object? If not, then what did you mean to use? Where does that value exist and how do you access it in that location?


#4

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