Question

In: Computer Science

with python Fatima wants to purchase a new dining table at an affordable price, so she...

with python
Fatima wants to purchase a new dining table at an affordable price, so she collected the models name, description and prices of different dining tables from IKEA website and stored them in the file DiningTables.txt.

The file contains records with the following format:

model_name(string)\ndescription\nprice (int)\n

Help Fatima get some statistics about the dining table records by performing the following tasks:

  • Read the file DiningTables.txt and print the number of records in the file.
  • Create a function called tables_statistics(file_name) that prints the records of the dining tables with the following criteria:
    • The most expensive dining table model name, description and price.
    • The cheapest dining table model name, description and price.
    • The average price of all dining tables in the file.

Here is a sample run for your reference:


—————-

TÄRENDÖ / GUNDE

Table and 4 chairs110 cm

231

TÄRENDÖ / ADDE

Table and 4 chairs110 cm

255

MELLTORP / ADDE

Table and 4 chairs125 cm

275

JOKKMOKK

Table and 4 chairs

595

LANEBERG / EKEDALEN

Table and 4 chairs130/190x80 cm

1375

LANEBERG / KARLJAN

Table and 4 chairs130/190x80 cm

1175

EKEDALEN

Table with 2 chairs and bench120/180 cm

1530

NORDVIKEN / LEIFARNE

Table and 4 chairs152/223x95 cm

1995

LERHAMN

Table and 2 chairs74x74 cm

495

EKEDALEN

Table and 4 chairs120/180 cm

1575

MÖRBYLÅNGA / LEIFARNE

Table and 6 chairs220x100 cm

3545

EKEDALEN

Table and 6 chairs180/240 cm

2165

IKEA PS 2012 / TEODORES

Table and 2 chairs

823

SKOGSTA / NORRARYD

Table and 6 chairs235x100 cm

3645

MELLTORP / TEODORES

Table and 4 chairs125 cm

491

MELLTORP / JANINGE

Table and 4 chairs125 cm

715

MELLTORP / TEODORES

Table and 2 chairs75x75 cm

273

MELLTORP / ADDE

Table and 2 chairs75 cm

165

INGATORP / INGOLF

Table and 4 chairs155/215 cm

1895

INGATORP / INGOLF

Table and 6 chairs155/215 cm

2685

INGATORP / INGOLF

Table and 6 chairs155/215x87 cm

3185

LANEBERG / SVENBERTIL

Table and 4 chairs130/190x80 cm

1295

NORDVIKEN / LEIFARNE

Table and 6 chairs210/289x105 cm

2745

NORDVIKEN

Table and 6 chairs210/289x105 cm

2865

NORDVIKEN

Table and 4 chairs152/223x95 cm

2075

MELLTORP / NILSOVE

Table and 2 chairs75x75 cm

785

MELLTORP / NISSE

Table and 2 folding chairs75 cm

265

MÖRBYLÅNGA / LEIFARNE

Table and 4 chairs140x85 cm

2995

VOXLÖV / ODGER

Table and 4 chairs180x90 cm

2175

EKEDALEN / ODGER

Table and 4 chairs120/180 cm

1975

MÖRBYLÅNGA / TOSSBERG

Table and 4 chairs145 cm

4275

GAMLARED / STEFAN

Table and 2 chairs85 cm

535

TINGBY / NILSOVE

Table and 4 chairs180x90 cm

2075

YPPERLIG / NILSOVE

Table and 4 chairs200x90 cm

2275

TINGBY / LEIFARNE

Table and 6 chairs180x90 cm

1745

MÖCKELBY / NORRARYD

Table and 6 chairs235x100 cm

4445

MÖCKELBY / ODGER

Table and 6 chairs235x100 cm

4265

VANGSTA / TEODORES

Table and 4 chairs120/180 cm

701

MÖRBYLÅNGA / BALTSAR

Table and 4 chairs140x85 cm

4475

MÖRBYLÅNGA / TOSSBERG

Table and 6 armchairs220x100 cm

5465

LISABO / SVENBERTIL

Table and 4 chairs140x78 cm

1295

MÖRBYLÅNGA / BALTSAR

Table and 6 chairs220x100 cm

5765

Solutions

Expert Solution

def tables_statistics(file_name):
    file1 = open(file_name,"r")
    l=[]
    l=file1.readlines();
    x=[]
    y=[]
    z=[]
    i=0
    while i<len(l):
        x.append(l[i])
        y.append(l[i+1])
        z.append(l[i+2])
        i=i+3
    print("Number of records in the file is:"+str(i/3))
    max=int(z[0])
    min=int(z[0])
    avg=0
    for i in z:
        if(max<int(i)):
            max=int(i)
        if(min>int(i)):
            min=int(i)
        avg=avg+int(i)
    avg=avg/len(z)
    ind=z.index(str(max))
    ind1=z.index(str(min)+'\n')
    print("\nThe most expensive dining table is")
    print(x[ind]+""+y[ind]+""+z[ind])
    print("\nThe cheapest dining table is")
    print(x[ind1]+""+y[ind1]+""+z[ind1])
    print("The average price of all dining tables in the file is:"+str(round(avg,5)))
fName="test.txt"
tables_statistics(fName)

Thank you! if you have any queries post it below in the comment section I will try my best to resolve your queries and I will add it to my answer if required. Please give upvote if you like it.


Related Solutions

Joan moves into her new apartment and wants to purchase a new couch. She wants to...
Joan moves into her new apartment and wants to purchase a new couch. She wants to determine if the average cost of couches at Store 1 is cheaper than Store 2. At Store 1 the average cost of 20 couches is $650 with a standard deviation of $61. At Store 2 the average cost of 22 couches is $730 with a standard deviation of $78. At alpha = .05, what are the results if you want to determine that Store...
Ms. Fatima is having a business and she wants to know the financial status of the...
Ms. Fatima is having a business and she wants to know the financial status of the business so, she decided to hire external auditor. The auditor Mr. Assad, pointed the highlights of his audit report: (1) inventories and receivable management are not properly done , (2) collection strategy is very poor (3) also the current asset management is not handled very well. Based on the above scenario: 1. Justify how GAAP can be applied in the Company of Ms. Fatima....
Megan is considering the purchase of a new car. She wants to buy the new Audi...
Megan is considering the purchase of a new car. She wants to buy the new Audi A1, which will cost her R347 500. She will finance 90% of the purchase price at an interest rate of 8% per annum, with monthly payments over three years. Interest is compounded monthly. How much money will she still owe on the loan at the end of one year
Glenn is selling food in restaurant. She is using POS system. So if she wants to...
Glenn is selling food in restaurant. She is using POS system. So if she wants to store the food sets in array, how to use search function to search the food sets from the array by using(( JAVA )) and display it ? I want a sample like this, thank you For example: Enter the set you want to search: SET1 SET1 $10 Cheese Burger Coke fries --------------------------------------------------------- Your Entire food menu : SET1 $10 Cheese Burger Coke fries SET2...
Milton Industries wants to purchase new equipment that has a quoted price of $1,000,000. Milton estimates...
Milton Industries wants to purchase new equipment that has a quoted price of $1,000,000. Milton estimates an additional cost of $95,000 will be needed today to have the equipment modified, shipped, and installed. The purchase of this additional equipment will require Milton to invest an estimated $65,000 in net working capital upfront, and this investment should be recovered when Milton sells the equipment. If purchased, the equipment will be employed for a total of five years, and then sold for...
Milton Industries wants to purchase new equipment that has a quoted price of $1,000,000. Milton estimates...
Milton Industries wants to purchase new equipment that has a quoted price of $1,000,000. Milton estimates an additional cost of $85,000 will be needed today to have the equipment modified, shipped, and installed. The purchase of this additional equipment will require Milton to invest an estimated $55,000 in net working capital upfront, and this investment should be recovered when Milton sells the equipment. If purchased, the equipment will be employed for a total of five years, and then sold for...
Milton Industries wants to purchase new equipment that has a quoted price of $1,000,000. Milton estimates...
Milton Industries wants to purchase new equipment that has a quoted price of $1,000,000. Milton estimates an additional cost of $95,000 will be needed today to have the equipment modified, shipped, and installed. The purchase of this additional equipment will require Milton to invest an estimated $65,000 in net working capital upfront, and this investment should be recovered when Milton sells the equipment. If purchased, the equipment will be employed for a total of five years, and then sold for...
Milton Industries wants to purchase new equipment that has a quoted price of $1,000,000. Milton estimates...
Milton Industries wants to purchase new equipment that has a quoted price of $1,000,000. Milton estimates an additional cost of $95,000 will be needed today to have the equipment modified, shipped, and installed. The purchase of this additional equipment will require Milton to invest an estimated $65,000 in net working capital upfront, and this investment should be recovered when Milton sells the equipment. If purchased, the equipment will be employed for a total of five years, and then sold for...
Milton Industries wants to purchase new equipment that has a quoted price of $1,000,000. Milton estimates...
Milton Industries wants to purchase new equipment that has a quoted price of $1,000,000. Milton estimates an additional cost of $95,000 will be needed today to have the equipment modified, shipped, and installed. The purchase of this additional equipment will require Milton to invest an estimated $65,000 in net working capital upfront, and this investment should be recovered when Milton sells the equipment. If purchased, the equipment will be employed for a total of five years, and then sold for...
Simmons Company is considering the purchase price of a new floor machine. The purchase price of...
Simmons Company is considering the purchase price of a new floor machine. The purchase price of the equipment is $420,000 and it is expected to have a useful life of 7 years with no salvage value. The company uses straight line depreciation and pays income taxes at a rate of 25%. If the company requires that all new equipment investments pay for themselves within 3 years, how much annual cash operating savings must the floor machine generate, if it is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT