85.4k views
2 votes
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.

1 Answer

4 votes

Answer:

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))

Step-by-step 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

User Austen Stone
by
4.1k points