Question

In: Computer Science

In accounting, balance sheets are used to keep of track how much money a person has...

In accounting, balance sheets are used to keep of track how much money a person has in an account.  Write a Python program to create a simple three column balance sheet, showing credits in one column, debits in the next, and a running balance in the third.  If the balance dips into the negative, you must show the value in parentheses, the standard method in accounting. Input will be from a text file. The first value will be the opening balance in the account, followed by an integer N indicating N sets of data to follow.  Each subsequent data set will be either the letter 'C' for credit, or 'D' for debit, followed by a dollar amount. Output to the screen a complete balance sheet, with headings and boundary lines above and below, and columns 14 spaces wide.  All amounts will be at least one dollar and are guaranteed to "fit" in the balance sheet.  All values with four digits or more in the whole number portion are to be output with "comma " notation, and all negative values in the balance column are to be shown in parentheses.

Let the user input the file name from the keyboard. Refer to the sample output below.

Sample File:

999.99

5

C 8250.55

D 12397.45

D 12345.67

C 15492.59

C 5000000

Sample Run:

Enter file name: account.txt

       DEBIT        CREDIT       BALANCE

-------------*-------------*-------------*

                            $      999.99

              $    8,250.55 $    9,250.54

$   12,397.45               $  (3,146.91)

$   12,345.67               $ (15,492.58)

              $   15,492.59 $        0.01

              $5,000,000.00 $5,000,000.01

-------------*-------------*-------------*

Solutions

Expert Solution

Solution:

Look at the code and comments for better understanding........

Screenshot of the code:

Output:

Code to copy:

#reading the filename from the user
filename = input("Enter file name : ")
file = open(filename)
#reading the first line from the file i.e balance
balance = float(file.readline())
#reading second line from the file i.e number of entries
N = int(file.readline())
#printing the table header
print("      DEBIT        CREDIT        BALANCE")
print(('-------------*')*3)
print("\t\t\t\t$ %.2f"%balance)
#looping upto N times
for i in range(N):
        #readin the line from the file and spliting it
        action,amount = file.readline().split()
        amount = float(amount)
        #for Credit amount
        if action=='C':
                balance += amount
                print('\t\t$ {:,.2f}\t$ {:,.2f}'.format(amount,balance))
        #for debit amount
        else:
                balance -= amount
                #if the balance is negative
                if(balance<0):
                        print('$ {:,.2f}\t\t\t$ ({:,.2f})'.format(amount,-balance))
                else:
                        print('$ {:,.2f}\t\t\t$ {:,.2f}'.format(amount,balance))

print(('-------------*')*3)

I hope this would help..............................:-))


Related Solutions

Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to...
A small insurance company, is trying to decide how much money to keep in liquid asset...
A small insurance company, is trying to decide how much money to keep in liquid asset to cover auto insurance claims. The company holds some of the premiums it receives in interest bearing checking accounts and puts the rest into investments that are not quite as liquid, but generate a higher return. The company wants to study cash flows to determine how much money it should keep in liquid assets to pay claims. A review of the company’s data has...
Consider the following set of requirements for a UNIVERSITY database that is used to keep track...
Consider the following set of requirements for a UNIVERSITY database that is used to keep track of students' transcripts. (a) The university keeps track of each student's name, student number, social security number, current address and phone, permanent address and phone, birthdate, sex, class (freshman, sophomore, ..., graduate), major department, minor department (if any), and degree program (B.A., B.S., ..., Ph.D.). Some user applications need to refer to the city, state, and zip of the student's permanent address, and to...
Explain why that plan is good for each person, including how much money they will save...
Explain why that plan is good for each person, including how much money they will save over the entire time of the loan and the amount of the new payments. Show the math. The original mortgage was 30 years at 7.5%, for 600,000. It was taken 4 years ago. PERSON 1 - Refinance: change to 15 years at 6.8% PERSON 2 - Refinance: For 30 years at 7.1%, reducing monthly payment. PERSON 3 - Don't refinance.
Explain using a series of balance sheets how the Fed can increase the money supply in...
Explain using a series of balance sheets how the Fed can increase the money supply in the economy.
How much money can Bank A create by making loans? How much money can the banking...
How much money can Bank A create by making loans? How much money can the banking system as a whole create? Show your detailed calculation. What can you say about the relationship between the required reserve ratio and money creation? Why do some banks hold a part in excess reserves instead of loaning all excess reserves out? What are some other ways that banks may use a portion of their excess reserves?
How are tome value money concepts used in accounting for valuing bonds that are held as...
How are tome value money concepts used in accounting for valuing bonds that are held as investments or issued by your company?
How can websites keep track of users? Do they always need to use cookies?
How can websites keep track of users? Do they always need to use cookies?
The oxygen atom has 4 electrons in the 2p shell. It's not easy to keep track...
The oxygen atom has 4 electrons in the 2p shell. It's not easy to keep track of the orbital and spin angular momenta of 4 electrons. Fortunately, there is a trick. You can think of oxygen as having a filled 2p shell with two "holes" in it. The holes act just like electrons: s = 1/2, l=1. So the holes in oxygen have the same possible configuration as the electrons in carbon. a) Neglecting spin-orbit coupling, make a table showing...
An owner of a football stadium is determining how much fertilizer is needed to keep the...
An owner of a football stadium is determining how much fertilizer is needed to keep the grass in the football stadium green. Thus, the owner collected the following data on how much fertilizer was used in 10 football stadiums from throughout the country. The unit of measurement is number of pounds per 1,000 square feet. Field Fertilizer 1 1.35 2 1.46 3 1.51 4 1.42 5 1.46 6 1.35 7 1.59 8 1.37 9 1.33 10 1.66 Prior to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT