Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q 1 ) [ 3 . 5 points ] Given a text file food.txt containing the availability of food items. food.txt is structured as follow:
Q points Given a text file food.txt containing the availability of food items. food.txt is structured as follow: the category, name, description, price and availability of a food item, separated by comma Download the data file named food.txt from the Exam Submission on Blackboard simply rightclick on the file name and choose 'Save as 'and browse to your GENG folder and save the file Create a new Python program named
qpy in which you define a main function. Perform the following in the main function:
Open the file, read all the records and store them in a D list called and then close the file.
afind the following:
The details of food with the category Fast food.
The details of food with the lowest price.
mavg which is the average ie the sum of prices divided by the number of food items
b Using list comprehension, create a new list named offer, where each element represents a discounted price; apply a discount of QAR to each food item's price in mdata.
c Sort the offer list in ascending order
d Write all the elements of offer in a file called questiontxt and close the file.
e Count and output the available foods only the available items in the following format: Number of available foods:
Details: name categorydescription: price
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started