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
#1
Can someone please help me i'm creating a code for an imitated bank account, what i'm trying to get it to is to basically display the name of the account holder and their current balance when a pre-determined pin number is entered into the account. But when run the code it seems to skip over the step to print the account holder's details, and print the error message when the right pin is entered in. Here's the code below. Any help would be appreciated, thanks

class BankAccount:
 
     # constructor or initializer
    def __init__(self, name, money):
         self.__name = name
         self.__balance = money   # __balance is private now, so it is only accessible inside the class
 
    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
 
b1 = BankAccount('Obi Ezeakachi', 5000)
b2 = BankAccount('Tasha St.Patrick', 80000)
b3 = BankAccount('Tommy Egan', 7000)
d1 = 0
d2 = 0
d3 = 0
pin1 = 1111
pin2 = 2222
pin3 = 3333
pin = input("Enter Pin")
if pin1 & pin:   
   print("Obi Ezeakachi: £",b1.checkbalance())
y1 = int(input("Enter 1 if you want to make a withdrawal, enter 2 if you don't"))
else:
   print("ERROR! TRY AGAIN")  
if y1 == 1:
   w1= int(input("How much do you want to withdraw"))
else:
   d1= int(input("How much do you want to deposit"))   
   print("Withdrawal: £",b1.withdraw(w1))
   b1.deposit(d1)   
   print("Current Balance:",b1.checkbalance())                                        
                                            
pin = input("Enter pin")
if pin2 == pin:  
   print("Tasha St.Patrick:",b2.checkbalance())
y1 = int(input("Enter 1 if you want to make a withdrawal, enter 2 if you don't"))
elif pin2 != pin:
    print("ERROR! TRY AGAIN")
if y1 == 1:
   w2= int(input("How much do you want to withdraw"))
   print(b2.withdraw(w2))
else:
   d2= int(input("How much do you want to deposit"))
   b2.deposit(d2)

if pin3 == pin:
   print("Tommy Egan:",b3.checkbalance())
y1 = int(input("Enter 1 if you want to make a withdrawal, enter 2 if you don't"))   
else:   
   print("ERROR! TRY AGAIN")
if y1 == 1:
   w3= int(input("How much do you want to withdraw"))
   print("Withdrawal:",b3.withdraw(w3))
else:
   d3= int(input("How much do you want to deposit"))
   b3.deposit(d3) 

print("Current Balance:",b3.checkbalance())
Reply


Messages In This Thread
Need help with pseuo -bank account using OOP - by obieze998 - Jul-08-2017, 05:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Different results of code with local account and technical account dreyz64 7 3,743 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