Ask Question
24 August, 02:09

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.

+4
Answers (1)
  1. 24 August, 04:02
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers