Ask Question
10 September, 19:41

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.

+3
Answers (1)
  1. 10 September, 20:06
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers