So I'm writing a personal bank tracker for myself, and I'm having a bit of trouble with a line of code. The ID_Pin method below is equal to 0000, however when i try to create an instance (any instance of the Account class), it returns the "Access Denied" bit that I wrote(ID_Pin), even when the instance pin matches the method pin. Any suggestions?

class Account:
    '''Wells Fargo.'''
    global balance 
    def __init__(self, name, pin_number, balance=100):
        self.name = name
        self.pin_number = pin_number
        self.balance = 100

    def alter_pin(self, enter_a_pin):
        '''To be used a later revision, changes a pin number.'''
        ID_List = []
        enter_a_pin.append(ID_List) 

    def ID_Pin(self):
        pin = 0000
        return pin  

    def get_balance(self, pin_number): 
        if pin_number == Account.ID_Pin:
            print("Balance: %d" % self.balance)
        else:
            print("Access denied: Incorrect PIN.")

    def withdraw(self,pin_number, amount):
        if pin_number == Account.pin:
            balance -= amount
            print("Withdrew  %d. New Balance: %d" % amount, balance)
        else:
            print("Access denied: Incorrect PIN.")

    def deposit(self, pin_number, amount):
        if pin_number == Account.ID_Pin:
            balance += amount
            print("Deposited %d. New Balance: %d" % amount, balance) 
            if balance <= 0:
                print("Balance limit reached!")
        else:
            print("Access denied: Incorrect PIN.") 

New_Bank_Account = Account("person",0000,100) 
New_Bank_Account.get_balance(0000)
New_Bank_Account.deposit(0000, 50000) 

Recommended Answers

All 7 Replies

Your code has a handful of mistakes and misconceptions. I corrected some of them to get this to work ...

class Account:
    '''Wells Fargo.'''
    #global balance 
    def __init__(self, name, pin_number, balance):
        self.name = name
        self.pin_number = pin_number
        self.balance = balance

    def alter_pin(self, enter_a_pin):
        '''needs work'''
        '''To be used a later revision, changes a pin number.'''
        ID_List = []
        ID_List.append(enter_a_pin) 

    def ID_Pin(self):
        '''needs work'''
        pin = 0000
        return pin  

    def get_balance(self, pin_number): 
        if pin_number == self.pin_number:
            print("%s has balance: %d" % (self.name, self.balance))
        else:
            print("Access denied: Incorrect PIN.")

    def withdraw(self,pin_number, amount):
        if pin_number == self.pin_number:
            self.balance -= amount
            print("Withdrew  %d. New Balance: %d" % (amount, self.balance))
        else:
            print("Access denied: Incorrect PIN.")

    def deposit(self, pin_number, amount):
        if pin_number == self.pin_number:
            self.balance += amount
            print("Deposited %d. New Balance: %d" % (amount, self.balance)) 
            if self.balance <= 0:
                print("Balance limit reached!")
        else:
            print("Access denied: Incorrect PIN.") 

# create unique account instances ...
jimmy = Account("Jim", 0000, 100) 
jimmy.get_balance(0000)
jimmy.deposit(0000, 50000)

print('-'*40)

betsy = Account("Elisabeth", 1234, 777) 
betsy.get_balance(1234)
betsy.deposit(1234, 7000)

''' result ...
Jim has balance: 100
Deposited 50000. New Balance: 50100
----------------------------------------
Elisabeth has balance: 777
Deposited 7000. New Balance: 7777
'''

Note that self is a reference to the particular instance of the class.

Yeah im sure it would have, im translating it from Ruby lol x_x, but thanks! :)

Man now that I look at it, I did make a lot of screwups, but it works just fine in Ruby. :O From now on, im just gonna write in either python or ruby, translating is not for me...yet.

Thanks Vega! :D

Translating too closely doesn't allow you to take adavantage of the chosen language's true power/elegance.

So is it wise just to not translate and just write each program in either Ruby or Python?

As long as you can make the program function the way you want. You learn a lot more that way.

Hmmm seems logical. Its just some things I find easier to write in ruby, some I find easier to write with python. I wish I could combine them. Rubython! lol.

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.