Python Forum
Help!! Help! python fake bank system
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help!! Help! python fake bank system
#1
Hi I am trying to create a fake python bank system. The program needs to be able to deposit, withdraw and check the balance. However when i run the code in python on mac the program seems to only loop the options over and over again

when i run the program and enter a number to select and option it brings me back to the same menu
for example

Welcome to the Python Bank System

Your Transaction Options Are:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1) Deposit Money
2) Withdraw Money
3) Check Balance
4) Quit Python Bank System.pyw
Choose your option: 3
Thank-You for stopping by the bank!
Welcome to the Python Bank System

Your Transaction Options Are:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1) Deposit Money
2) Withdraw Money
3) Check Balance
4) Quit Python Bank System.pyw
Choose your option: 4
Thank-You for stopping by the bank!
Welcome to the Python Bank System

Your Transaction Options Are:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1) Deposit Money
2) Withdraw Money
3) Check Balance
4) Quit Python Bank System.pyw
Choose your option:


#THIS PART IS NOT THE CODE ITSELF THESE ARE JUST COMMANDS
def menu():
        money = int(5000)
        money = float(money)
    #print the options you have
        print ("Welcome to the Python Bank System")
        print( " ")
        print ("Your Transaction Options Are:")
        print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        print ("1) Deposit Money")
        print ("2) Withdraw Money")
        print ("3) Check Balance")
        print ("4) Quit Python Bank System.pyw")
        print
        return input ("Choose your option: ")
#Here is the deposit part.... This is where the user inputs the amount of money
#they wish to deposit into their account.
def deposit(money):
        global balance
        deposit = input("How much: $")
        deposit = float(deposit)
        if deposit <= money:
            balance = balance + 1
            money = money - deposit
            money = float(money)
            deposit = deposit * .1
            deposit = float(deposit)
            balance = deposit + balance
            balance = float(balance)
            print ("depositing balance = %7.2f,  money = %7.2f" % (balance, money))
            print
            bank_balance(balance)
            return balance
#This is where the user inputs the amount of money they wish to withdraw from
#their account. Currently not programmed in as of yet.
def withdrawl(balance, money):
        print ("Sorry, but this function is currently under construction!")
        print
        return
#This is an obvious one, this is where you check your balance.
def bank_balance(balance):
        print ("Balance: $", balance)
        return balance
# NOW THE PROGRAM REALLY STARTS, AS CODE IS RUN
balance = 0
balance = float(balance)
money = 5000
money = float(money)
loop = 1
choice = 0
while loop == 1:
    choice = menu()
    if choice == 1:
        deposit = deposit(money)
    elif choice == 2:
        withdraw = withdrawl(balance, money)
    elif choice == 3:
        balance = bank_balance(balance)
    elif choice == 4:
        loop = 0
    print ("Thank-You for stopping by the bank!")
#END OF THE PROGRAM
Reply
#2
If you are running this in Python 3.0 or higher, input returns a string. So choice is a string, and you are comparing it to integers, which will never match. Either convert choice to an integer with int(), or compare it to strings like '1', '2', and so on.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Oct-04-2017, 07:21 PM)ichabod801 Wrote: If you are running this in Python 3.0 or higher, input returns a string. So choice is a string, and you are comparing it to integers, which will never match. Either convert choice to an integer with int(), or compare it to strings like '1', '2', and so on.

Hi, Thank you for the response. How would i do that could you please explain it more?
Reply
#4
>>> one = '1'
>>> one
'1'
>>> one + 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be str, not int
>>> int(one)
1
>>> int(one) + 1
2
>>> one == 1
False
>>> int(one) == 1
True
>>> one == '1'
True
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is it possible to make a bank transfer with python? funkynerd 3 3,552 Nov-30-2020, 09:20 PM
Last Post: Marbelous

Forum Jump:

User Panel Messages

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