Bank account project


so this could be really confusing(i’m confused with my own code bcs it’s very long.) so, i’m trying to make bank account project but with def/if. so my code runs well. well, sometimes. i don’t get it sometimes i got the value right, sometimes wrong. example: i tried to deposit 3000 to ‘MICHELLE’ account and it printed ‘MICHELLE:4000’ but sometimes it doesn’t print ‘MICHELLE:4000’ even tho i never change the code. is it because my computer or the code is too long? help. Thankyou very very much.



Please copy paste your full code to the forum, working from screenshots is really difficult.

bank_money = {'MICHELLE':'1000','VINCENT':'350','FELICE':'600'}

from time import sleep,strftime

def banksystem():
        print("Welcome to your own bank account! please enter your information!")
        name = input('Please enter your name here..')
        name = name.upper()
        print('First confirmation..') #phase 1 identity confirmation
        for names in bank_dict:
            if name == names:
                print('Pass! your name is in here! welcome %s !' % names)
                name_id = input('Please enter your ID number here(ex:0x)..')
                print('Second confirmation..') #phase 2 identity confirmation 
                if name_id == bank_dictx[name]:
                    print('Pass! your ID number is %s!'%name_id)
                    choice = input("You can either withdraw 'W'/ deposit 'D'/Transfer 'T'/ Quit 'X'")
                    choice = choice.upper()
                    if choice == 'W':
                        withdraw= int(input('How much withdrawal?')) #withdrawal
                        if withdraw > int(bank_money[name]):
                            print('Sorry your balance isn\'t sufficient enough! Your balance is : $%s' % bank_money[name])
                            bank_money[name] = int(bank_money[name]) - withdraw
                            return name + ': $' + str(bank_money[name])
                    elif choice == 'D':
                        deposit=int(input('How much is your deposit?')) #deposit
                        if deposit>0:
                            bank_money[name] = int(bank_money[name]) + deposit
                            return name + ': $' + str(bank_money[name]) + ' Updated at: ' + strftime("%H:%M:%S | %A %B %d, %Y")
                            print('INVALID CASH DEPOSITED.')
                    elif choice == 'T': #transfer
                        transfer = int(input('How much you want to transfer?'))
                        receiver = input('to whom? (only can transfer to people in this bank)')
                        receiver = receiver.upper()
                        if int(bank_money[name])<transfer :
                            print('Sorry your balance isn\'t sufficient enough! Your balance is : $%s' % bank_money[name])
                        elif transfer<1:
                            print('INVALID CASH TRANSFERRED.')
                        elif transfer>0:
                            for receivers in bank_money:
                                if receivers == receiver:
                                    bank_money[receiver] = int(bank_money[receiver])+transfer
                                    bank_money[name] = int(bank_money[name])-transfer
                                    return "you have succesfully transferred $" + str(transfer) + " to " + receiver + "'s bank account! your balance now is :$" + str(bank_money[name])
                                return 'THE ACCOUNT DOES NOT EXIST!'
                    elif choice == 'X': #quit
                        return 'THANKYOU!'
                        print('INVALID COMMAND.')



unable to reproduce problem? Tried 3 times

the largest problem with your code is that everything is within the banking function, which is not good for readability. Maybe you should split your code over multiple function? Like a separate function for withdraw and a separate function for deposit?


Thankyou!!! that’s really helpful!


can i ask another thing? i have learned python in codeacademy and what’s left on my exercise is the final project and practice makes perfect exercise. but sometimes my logic doesn’t work even tho i have already try to think the solution for 3 hours, and i give up and i see the solution. understanding the solution is not hard for me, but is it i’m stupid because i cannot solve simple problems?


yep, the tricky bit is to actually solve the problem before seeing it. Programming is a lot of problem solving. Which is very difficult in the beginning, so no, certainly not a shame.

The tricky bit is to teach yourself how you can solve problems like that. Break the problem in small steps? What data types do i need? Loop? Logic?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.