Answered step by step
Verified Expert Solution
Link Copied!

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:

Q1)[3.5 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 right-click on the file name and choose 'Save as...' 'and browse to your GENG106 folder and save the file). Create a new Python program named
q1.py 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 2D list called m?data, and then close the file.
a.find the following:
The details of food with the category Fast food.
The details of food with the lowest price.
m_avg which is the average i.e. the sum of prices divided by n(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 10QAR to each food item's price in m_data.
c. Sort the offer list in ascending order
d. Write all the elements of offer in a file called question1.txt, 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 (category)-description: price
image text in transcribed

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions