Editor

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:

  • 1 deposit: read an amount and print Deposited 500. Balance: 1500
  • 2 withdraw: read an amount and print Withdrew 200. Balance: 1300, or Not enough money. Balance: 1300 if the amount is more than the balance
  • 3 print Balance: 1300
  • 4 print Goodbye. Final balance: 1300 and 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.