Bank Account Menu
Programs with input · Advanced · about 20 min
Read the starting balance, a whole number. Then read a menu choice again and again until the choice is 4:
1deposit: read an amount and printDeposited 500. Balance: 15002withdraw: read an amount and printWithdrew 200. Balance: 1300, orNot enough money. Balance: 1300if the amount is more than the balance3printBalance: 13004printGoodbye. Final balance: 1300and stop- anything else: print
Invalid choice
Amounts are whole numbers. A deposit or withdrawal of 0 or less is refused with Amount must be more than 0, and the balance stays the same. Writing a function for deposits and one for withdrawals keeps the loop short.
The prompts inside input() are not checked, only what you print.
Example
You type:
1000 1 500 2 200 3 4
The program prints:
Deposited 500. Balance: 1500 Withdrew 200. Balance: 1300 Balance: 1300 Goodbye. Final balance: 1300
balance = int(input("Starting balance: "))
# Read a menu choice again and again, and handle each one, until the choice is 4
The solution opens after your first Check.