Classes: Bank Account:

Hi, all! This is my first time posting to these forums, so please go easy on me. I am working on project , and am having trouble. Can someone please advise? Thank you. My code is below. Oh, jeez, after posting it isn’t saving the indentation.

class BankAccount(object):
  balance = 0
  def __init__(self, name): = name
  def __repr__(self):
    return "Hello, %s. Your balance is $%s.2f" % (, self.balance)
  def show_balance():
    print balance
  def deposit(self, amount):
    self.amount = amount
    amount = raw_input("What would you like to deposit?")
    if amount <= 0: 
      print "You can't deposit negative money!"
      print "You are depositing $%s.2f" % (amount)
      balance += amount
  def withdraw(self, amount):
    self.amount = amount
    amount = raw_input("How much would you like to withdraw?")
    if amount > balance: 
      print "You can't withdraw that much money!"
      print "You are withdrawing $%s.2f" % (amount)
      balance -= amount
my_account = BankAccount("Aliesha")

Hi Aleisha, welcome to the forums! Thanks for including your code and a link to the exercise, I’m sure that a fellow member of the community will be by to help.

With regards formatting your code, take a look at this post to learn more about backticks and how they can help you to format. It’d also be helpful if we got some more info on what exactly you’re having problems with. Are you getting an error code? What step are you on? What are you trying to do that you’re struggling with? Have you watched the walkthrough video and if so what did it not answer?

1 Like