Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python program to produce a report from an input text file with records (lines) ordered by brand name. Input: shoeFile ( shoe.txt )

Write a Python program to produce a report from an input text file with records (lines) ordered by brand name. Input: shoeFile ("shoe.txt") The comma-separated record fields are brand, model and price. Data are to be sorted by brand. For testing place a copy of this file in the folder with your .py program. The unsorted lines of comma-separated data are listed below: Rockport,Eureka,50.14 Slow Man,Sock Sneaker,23.88 Larnmern,Safety Shoe,53.95 Under Armour,Running,55.10 Adidas,Ultraboost,127.00 Asics,Trail, 55.50 Skechers,Afterburn,51.52 OTU,Walking,19.99 Brooks,Adrenaline,109.95 New Balance,Cross Trainer,56.95 Ryka,Walking,73.17 Processing: Define getShoeList: a function to open "shoe.txt" as shoeFile for reading, create an empty shoeList, then assign to shoeList the entire file returned by readlines() reading the entire file into shoeList, sorting shoeList, then returning shoeList to the caller. Within "main" initialize variables such as an index and an accumulator; print report title and column heading lines; assign to shoeList the value returned from getShoeList(); while there is another shoeList element (e.g. index less than length): assign to lineList the values from spliting a shoeList element into fields for brand, model and price; increment shoe count; add price to an accumulator variable; print a formatted detail line; calculate average shoe price; print a formatted footing line with shoe count and average price. Output: A printed report with title, column heading, detail lines and a footing line with shoe count and average price. (Prices should be decimal-aligned). Expected output: Shoe Catalog Brand Model Price Adidas Ultraboost 127.00 Asics Trail 55.50 Brooks Adrenaline 109.95 Larnmern Safety Shoe 53.95 New Balance Cross Trainer 56.95 OTU Walking 19.99 Rockport Eureka 50.14 Ryka Walking 73.17 Skechers Afterburn 51.52 Slow Man Sock Sneaker 23.88 Under Armour Running 55.10 Shoe count = 11 Average price: 61.56 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Dimensions of integrated marketing communications

Answered: 1 week ago