1. Engineering
  2. Computer Science
  3. in python 30 please the owners of a corner store...

Question: in python 30 please the owners of a corner store...

Question details

In Python 3.0 please

The owners of a corner store in a rural area allow their customers from the village to purchase on credit any item in the store. When a purchase is done on credit, it is recorded in a file. The phone number of the family, the date of purchase and the amount due are recorded. Any member of a family in the village can come anytime and make a payment towards what is due, or even an advance. The phone number of the family, the date of the payment and the amount are recorded in a separate file. The owners noticed that some of the customers often still owe them a large amount at the end of the month. They decided to stop providing credit to families that owe them more than $500 at the end of the month and add interest of 1% to any family that owe them more than $100 at the end of the month.

You meet the owners of this store who ask you to assist them by writing a python program that would generate a report at the end of the month given three files as input.

The first file families.txt contains the list of known customers from the community. The file has their phone number, name of head of family and their address. The file has in each line a phone number, a full name and an address separated by ",”. The file content looks like this:

7804922860,Osmar Zaiane,32 Alphonse Street
7801234567,Robert Post,66 Hinton Road
7809876543,Farrukh Ahmed,101 Edson Crest
7803214567,Md Toukir Imam,34 Sherwood Park Avenue
7807890123,Elham Ahmadi,8 Devon Place
7808907654,Rong Feng,32 Spruce Street
7801236789,Nazanin Tahmasebi,98 Albert Avenue
7804321098,Sayem Mohammad,56 Stony Place
7809001234,Alfred Baali, 3 Tijani street
7808765432,Amir Hossein,45 Beautiful Street

The second file dues.txt, contains information about the purchases that were bought on credit. Each line contains a date, the amount due, and the phone number of the family who did the purchase, all separated by ";”. The date is formatted YYYY/MM/DD. The file looks like this.


The third file payments.txt, contains information about payments. Its structure is similar to the second file. Each line contains a date, the amount paid, and the phone number of the family who did the payment, all separated by ";”.:

You are required to write a program that would generate a file, call it summary.txt, that can be printed and contains a table listing the customers that purchased credit and that made payments with their total dues and the list of payments they did. The table should be formatted as follows and the list of payments with the dates should be outside the table on the right.

Your program should read the three files and produce a table formatted as follows:

| Phone Number | Name             | Due    | Int |
|(780) 123 4567|Robert Post       |$  92.70|     |
|(780) 123 6789|Nazanin Tahmasebi |$  22.25|     | [$30.00] 2018/11/30 ($30.00);
|(780) 321 4567|Md Toukir Imam    |$  84.75|     | 
|(780) 432 1098|Sayem Mohammad    |$  25.25|     | [$15.50] 2018/11/25 ($5.5); 2018/11/30 ($10.00);
|(780) 492 2860|Osmar Zaiane      |$  91.22|     |
|(780) 789 0123|Elham Ahmadi      |$ 111.30|$1.10| [$42.50] 2018/11/30 ($42.50); 
|(780) 876 5432|Amir Hossein      |$ 148.47|$1.47| 
|(780) 890 7654|Rong Feng         |$ 130.99|$1.29| 
|(780) 900 1234|**Alfred Baali    |$ 517.22|$5.12|
|(780) 987 6543|Farrukh Ahmed     |$  26.25|     | [$50.00] 2018/11/30 ($50); 
| Total Dues   |                $    729.32|
| Total Interes|                  $    3.86|

The table has 4 columns and is sorted by the phone number.

  • The first column is the phone number. This number has to be formatted as (999) 999 9999.
  • The second column is the name and it has to be 18 characters wide. If the name is longer, the name is truncated to fit. In addition, the name is prefixed with "**" if the amount due is higher than $500.
  • The third column is the amount due. This amount should be printed with 7 positions and only 2 after the decimal point. Note that the amount due should be increased by the interest if the initial amount is higher than $100.
  • The fourth column is the interest due which should be printed with 4 positions and only 2 after the decimal point. The interest should not be printed if equal to zero.
  • Moreover, alongside the table and on the same row of the customer, we need to have the list of payments with the dates they were made formatted as per the example table. The list is preceded by the total paid between square brackets. All amounts should be formatted with 2 numbers after the decimal point.
  • Finally, two lines at the end of the table should indicate the total amount due by the whole community and the total interest incurred by all the customers. The table should be formatted as illustrated above.

In addition to the output file, the same output should also appear on the screen.

Note that the example output table is not exactly related to the two input examples provided here. Indeed the output depends on 3 input files. The input provided here is just an example. You should create your own 3 files and stick to the structure described here.

Also note that the "Total Interest" is written without the "t". It is intentional. This is what the customer wants.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution