Ask Question
23 February, 04:13

Write a Python program to balance a checkbook. The main function needs to get the initial balance, the amounts of deposits, and the amounts of checks. Allow the user to process as many transactions as desired; use separate functions to handle deposits and checks.

+5
Answers (1)
  1. 23 February, 08:08
    0
    def deposit (deposit_amount, balance):

    balance + = deposit_amount

    return balance;

    def process_check (check_amount, balance):

    balance - = check_amount

    return balance;

    balance = float (input ("Enter the initial balance: "))

    transaction = input ("Choose transaction method - D to deposit, C to process check, Q to quit: ")

    while transaction! = 'Q':

    if transaction = = 'D':

    deposit_amount = float (input ("Enter amount to be deposited: "))

    balance = deposit (deposit_amount, balance)

    print ("Current balance is: " + str (balance))

    elif transaction = = 'C':

    check_amount = float (input ("Enter amount to process check: "))

    if balance > = check_amount:

    balance = process_check (check_amount, balance)

    print ("Current balance is: " + str (balance))

    else:

    print ("Not enough money!")

    else:

    print ("Invalid input!")

    transaction = input ("Choose transaction method - D to deposit, C to process the check, Q to quit: ")

    print ("Your final balance is: " + str (balance))

    Explanation:

    - Create functions to handle deposits and checks

    - Ask the user for the initial balance and transaction to be made

    - Initialize a while loop iterates until the user enter Q

    - Ask the deposit amount or check amount depending on the transaction chosen

    - Calculate and print the current balance for each transaction

    - Print the final balance
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a Python program to balance a checkbook. The main function needs to get the initial balance, the amounts of deposits, and the amounts ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers