shutdown = False balance = float( 500.50) format (balance, '.2f') def inputnumber (message): '''This function ensures that only numbers may be put in as a valid input, anywhere in the program.''' try: val = float(input(message)) except ValueError: return -1 return val def printbalance (): '''this prints the Balance to the user''' print ("Your current balance is: ") print (balance) def fastcash (): '''determines if the user's account has at least 50$, then draws that out''' global balance fast = 50 if balance < (50): print ("Sorry, but you do not have enough funds to process this transcaction.") else: print ("Dispensing fast cash ($50)") balance -= fast def deposit (): '''This adds the user inputted float to the balance''' global balance deposited = inputnumber("How much would you like to deposit? ") if deposited <= (0): print ("That is not a valid amount") elif deposited >= (0): balance += deposited print ("deposit complete. Balance updated") else: print ("Error. That is not a valid input") def withdrawbalance (): '''This function withdraws funds from the user's account balance. If the balance is too low, it returns an error.''' global balance withdraw = inputnumber("How much would you like to withdraw?: ") if withdraw < balance: print ("Transaction complete. Dispensing money.") balance -= withdraw else: print ("Insufficient funds.") while (shutdown == False): #added in to keep refreshing the menu after an action is made/input is made print (" ") print ("menu") print (" ") print ("1 = Make a deposit") print ("2 = Make a withdrawal") print ("3 = view balance") print ("4 = Fast Cash ($50)") print ("5 = quit program") userchoice = inputnumber("What would you like to do?: ") if (userchoice ==1): deposit () elif (userchoice ==2): withdrawbalance () elif (userchoice ==3): printbalance () elif (userchoice ==4): fastcash() elif (userchoice ==5): print ("Thank you for banking with us") quit shutdown = True else: print ("Error")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question