I need to make an object called Accounts that can be used as a banking system. It requires 3 inputs, first name, last name, and initial deposit and 4 member functions: withdraw, deposit, fee and interest. The fee is $20 a month if the amount in the account is less than $100. The interest is 5%.

Just wanted to see if I was headed in the right direction, so here's what I've got so far.

class Accounts(object):
    def __init__(self, first, last, dep=0):
        self.first = first
        self.last = last
        self.dep = dep
    def deposit(self, amount):
        self.dep += amount
        return self.dep
    def withdraw(self, amount):
        if amount <= self.dep:
            self.dep -= amount
            return True
        else:
            return False
    def fee(self, amount):
        if self.dep - amount < 1000:
            self.dep -= (amount + 10)
        return self.dep
    def interest(self):
        return self.dep * 0.3
    def final(self):
        s = Accounts("John", "Doe", 1500)
    print ("%s, %s, balance: %s") % self.first, self.last, self.dep

Also, I'm using Python 3.3.

__init__, withdraw and deposite are fine. Though I would call dep something better, like deposite or balance.

def fee(self, amount):
    if self.dep - amount < 1000:
        self.dep -= (amount + 10)
    return self.dep

Uh, wern't the values $100 and $20? Also, what does amount have to do with anything? If there is less then $100 deposited, the fee is $20.

 def interest(self):
    return self.dep * 0.3

Again, the value was supposed to be 0.5, correct?

Also I'm assuming that fee and interest are both automatically called at the end of the month?

Also, you probably shouldn't put final or that print statement in the class, since that's the code that ends up using the class.

Whoops, I forgot to change those values in my code, my apologies.

Yes, the fee and interest are automatically called at the end of the month. So how would I go about making a final statement showing what the person will have left in their bank account?

class Accounts(object):
    def __init__(self, first, last, balance=0):
        self.first = first
        self.last = last
        self.balance = balance
    def deposit(self, amount):
        self.balance += amount
        return self.balance
    def withdraw(self, amount):
        if amount <= self.balance:
            self.balance -= amount
            return True
        else:
            return False
    def fee(self):
        if self.balance < 100:
            self.balance += 20
        else:
            return self.balance
    def interest(self):
        return self.balance * 0.5

This is what I've gotten thus far now.

So how would I go about making a final statement showing what the person will have left in their bank account?

The problem with your original final is this: s = Accounts("John", "Doe", 1500). Why would you make a method that is already aware of the bank owners name? That doesn't make sence, because then Accounts will only work for John Doe. Put that print statement in final and that's it. Remove the other line from final.

Also, then name Accounts implies that it's more then one account, but your class only works for 1 account. And the name final isn't decriptive enough. If you want to make a method that prints out the account information, call it printAccountInformation or something simular.

Every time I try to run Accounts, it just gets this error:
<main.Accounts object at 0x00000000030E8DA0>

It's not an error. It looks like your trying to print an Accounts object (which should be named Account).

Python out of the box has no idea how to print an accounts object. So your can either print the invidual fields yourself, or you can implement Account.__str__() (which returns a string version of Account) yourself.

Got that all figured out now, thank you. Now how can I make it so that the interest will minus out of the total balance that it has?

BTW, 5% is 0.05.

interest will minus out of the total balance that it has?

You mean write a function that subtracts the insterest from the total balence?

That's basic arithmetic. Calulate the interest, and subtract it from the total.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.