Python Forum
Need help with pseuo -bank account using OOP
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with pseuo -bank account using OOP
#21
then how is it supposed to look like
Reply
#22
return data[pin]
Not

return True
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#23
(Jul-23-2017, 11:04 PM)ichabod801 Wrote:
return data[pin]
Not

return True

d1 = 0
d2 = 0
d3 = 0
y1 = 0
w1 = 0
pin = 0
class Bank_Account: 
    def pincheck(self, pin):
       if pin in  data:
           data[pin]
           return data[pin]
       else:

          return False
          print("WRONG PIN")
     # constructor or initializer
    def __init__(self, name, money, pin1):
         self.__name = name
         self.__balance = money   # __balance is private now, so it is only accessible inside the class
         self.__pin = pin1
         

    def deposit(self, money):
         self.__balance += money
 
    def withdraw(self, money):
         if self.__balance > money :
             self.__balance -= money
             return money
         else:
             return "Insufficient funds"
 
    def checkbalance(self):
         return self.__balance
    def next_step():
        while True:
              y2 = int(input("Enter 1 if you want to make a withdrawal, enter 2 if you don't"))
        if y2 == 1:
           enter_pin()
        else:
            print("ERROR, TRY AGAIN")


Bone = Bank_Account('Obi Ezeakachi', 5000, 1111) 
Btwo = Bank_Account('Tasha St.Patrick', 80000 , 2222)
Bthree = Bank_Account('Tommy Egan', 7000, 3333)

data = {'1111':  Bone  , '2222' :  Btwo , '3333' :  Bthree }
data = {int(pin):value for key, value in data.items()}

def enter_pin():
     while True:
      pin = int( input("Enter pin "))# keeps asking for the correct pin 
      if pin in data:
         data[pin]
         return data[pin]
      else:
       print("INCORRECT PIN TRY AGAIN") 

still gives " Incorrect pin try again whenever i try to enter any of the pins"





 **snooty** 
Reply
#24
You seem to be having difficulty grasping the idea of functions.
Go back and read post 12 very carefully. You say you are following what was written here,
but you are not.
Reply
#25
the thing is i don't understand how his example can relate to my own code, UPDATE: after re-reading post 12 things are making a little more sense will try again and get back to you.
Reply
#26
which part doesn't fit?
what Ichabod801 shows uses your data structures,
and supplies the result that you need for the affected portion of your code.
Reply
#27
def enter_pin():
     while True:
      pin = int( input("Enter pin "))# keeps asking for the correct pin 
      if pin in data:
         d = data[pin]
         while True:
    
             return data[pin]
       if pin[0] in 'qQ':
            break
       else:
           print("INCORRECT PIN TRY AGAIN")


My code currently looks like this

right it's throwing an issue with if pin[0] in 'qQ':, saying the int' object is not subscriptable
Reply
#28
You PM'd:
Quote:hi could you take a look at my code again for me please. Any advice would be good

Please post rather than PM so all can share.
  • 1. - Get rid of the while True: on line 6      This is going to loop forever and try to return each time
  • 2. - You don't need line 5 it serves no purpose. Git rid of that too
  • 3. - Your indentation is messed up, but that may be the result of a forum editor issue that was recently discovered
  • 4. - Finally and most importantly, go back and use Ichabod801's suggestion. I think you will be pleasantly surprised
             If you don't try this, I think you need to run a beginning tutorial of functions and classes.

Take this to heart, you've been ignoring very good advise to this point.
Reply
#29
Do NOT PM (No Personal Mail)
You need to share!!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Different results of code with local account and technical account dreyz64 7 3,594 Mar-05-2020, 11:50 AM
Last Post: dreyz64

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020