Need help with bank account program


#1

When run the code keeps throwing a syntax error when using input() to ask how much the person wants to withdraw from their account, any help is appreciated

pin = int( input("Enter pin "))
class BankAccount:
 
     # 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 pincheck(self, pin):
        if pin == data:
           return True
        else:
            return False;
    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, 1111)
b2 = BankAccount('Tasha St.Patrick', 80000 , 2222)
b3 = BankAccount('Tommy Egan', 7000, 3333)
d1 = 0
d2 = 0
d3 = 0
y1 = None
w1 = 0 
data = {'1111': b1 , '2222': b2, '3333': b3}

if b1.pincheck(pin):
   
 print("Obi Ezeakachi: £",b1.checkbalance())
 y1 = int(input("Enter 1 if you want to make a withdrawal, enter 2 if you don't")
if y1 == 1
   input("How much do you want withdraw")      
   w1 = int(input())
   print("Withdrawal: £",b1.withdraw(w1))
else:
   d1= int(input("How much do you want to deposit"))   
   b1.deposit(d1)   
   print("Current Balance:",b1.checkbalance())
   
if b1.pincheck(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"))
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 b1.pincheck(pin):
    
   print("Tommy Egan:",b3.checkbalance())
y1 = int(input("Enter 1 if you want to make a withdrawal, enter 2 if you don't"))   
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)

#2

missing colon at the end on the line above the error message


#3

did it now it says i have an invalid syntax


#4

look at the parentheses on the line above (line 42) your error message (line 43), pay close attention to the parentheses.


#5

i still don't see it, are you talking about if y1 == 1:


#6

no, the line above it. Look at your parentheses.

Please explain why this was not clear, i even included line numbers


#7

Took me a bit to understand what you were saying too.
@o998 has:

if b1.pincheck(pin):
 print("Obi Ezeakachi: £",b1.checkbalance())
 y1 = int(input("Enter 1 if you want to make a withdrawal, enter 2 if you don't")
if y1 == 1:
   input("How much do you want withdraw")
   w1 = int(input())
   print("Withdrawal: £",b1.withdraw(w1))
else:
   d1= int(input("How much do you want to deposit"))   
   b1.deposit(d1)   
   print("Current Balance:",b1.checkbalance())

the following line is missing a parenthesis. it has two opening parens and only one closing paren
y1 = int(input("Enter 1 if you want to make a withdrawal, enter 2 if you don't")


#8

ok done that but now it skips over y1 = int(input("Enter 1 if you want to make a withdrawal, enter 2 if you don't"))
if y1 == 1:
input("How much do you want withdraw")
w1 = int(input())


#9

we helped you with two issues, please try debug a bit yourself again given you now face a new issue


#10

i've been stuck on this issue for about 2 weeks now i wouldn't be asked for others help if i seriously couldn't do it


#11

here:

   def pincheck(self, pin):
        if pin == data:
           return True
        else:
            return False;

the comparison won't work. pin is a integer, data is a dictionary. They will never equal.

i hope you haven't been stuck two weeks at a missing colon and parenthes


#12

Seeing as I am new to helping on the forums, I will defer to stetim94 on this and leave you with this tip:

You have a really big program here, with lots of stuff.
Try breaking it up into little sub-problems.
If a chunk can work by itself, try to make sure it works the way it should.
If it doesn't, try re-coding that little chunk from scratch.
If it is a simple I-missed-some-syntax error, you generally won't make it twice in a row

Otherwise, I pull out a pencil and paper (yep, I'm a little old-fashioned) and try to write down exactly what I think the thing is doing.
I then insert a bunch of print statements to see everything relevant to the process that isn't working (that I can think of) to figure out why it isn't doing what I think it is.

I hope this helps with future bug problems


#13

Why stop? If you can have valuable insight, your contribution would be more then welcome :slight_smile:


#14

No I meant i've been building this code over time from another program. Adding things as I go along


#15

Then what shall I do instead


#16

don't know, i don't know how the program needs to look in the end. I can tell you where you go wrong, but its really difficult to correct something, given i have no idea where the program is headed.

you could use .get() to see if key is in dictionary.

Also, here:

data = {'1111': b1 , '2222': b2, '3333': b3}

keys can also be integers, they should be in this case, given pin is also a integer


#17

How the code should end up is that you enter a pin for one of the accounts. When the program has found the pin it prints the name and balance of the account holder, then asks the option of whether you want to make a deposit or a withdrawal, based on what is picked, it will print the final balance. What I need to now is fix the issues I've stated above and do the next 3 things:

After transactions are done with one account, the option to exit the account needs to be implemented

Get the program to be in a loop so it keeps asking for the pin, if you enter the wrong pin.

Be able to add and delete accounts


#18

In response to the dictionary how do I make the intended and dictionary equal values. What can I use to make a key to link to each account


#19

You can't expect me to help with all those issues

Sure, i help people on the forum even if its not exercise related, but if you need help with all that, you might want to hire a programmer to help you.

what is wrong with using .get()?

Don't expect me to program that, that is programming, i am helping for free, i am not programming for free


#20

hm. let's make a breakdown of what you want the code to do:

you want to store and interact with people's data
- dictionaries and classes work well for this.
you want to have the GUI loop
- perhaps something like a while shouldContinue: loop thingie (shouldContinue would be a boolean)
- corollary: need to have a loop exit condition
you want to be able to do a loot of different things with the data
- perhaps nest your GUI loops.
- you could have a master loop where the user chooses if they want to (a) make a transaction, (b) add/delete an account, or (c) exit the loop
- you could then have mini loops as needed within those processes
- I would suggest that you make the actions chosen from the master loop functions, just to make the structure easier to work with