Create a program in Python that reads data from Breakfast Menu (https://www.w3schools.com/xml/simple.xml) and builds parallel arrays for the menu items, with each array containing the menu item name, description, calories, and price, respectively. After reading the data and building the arrays, display the menu items similar to the following:     name - description - calories - price

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I NEED HELP PLEASE

NO REGEX OR ANYTHING COMPLICATED PLEASE.. USE BASIC APPROACH

 

Create a program in Python that reads data from Breakfast Menu (https://www.w3schools.com/xml/simple.xml) and builds parallel arrays for the menu items, with each array containing the menu item name, description, calories, and price, respectively. After reading the data and building the arrays, display the menu items similar to the following:

    name - description - calories - price

At the bottom, display the total number of items on the menu, the average number of calories per item, and the average price per item similar to:

    0 items - 0 average calories - $0.00 average price

 

You may either read the page using Internet processing methods, or you may download and save the page and then read the data from the saved file. You must process the data using string functions (no XML libraries).

must use separate subroutines/functions/methods to implement each type of processing, and include error handling for missing or invalid data.

 

THE BREAKFAST MENU IS BELOW:

<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
 
 

WHAT I HAVE SO FAR BELOW:

def read_data():
    with open("simple.xml", "r") as file:
        string = file.read()

def extract_data(tag, string):
    data = []
    start_tag = f"<{tag}>"
    end_tag = f"</{tag}>"
    while start_tag in string:
        start_index = string.find(start_tag) + len(start_tag)
        end_index = string.find(end_tag)
        value = string[start_index:end_index]
        data.append(value)
        string = string[end_index + len(end_tag):]
    return data

def get_data():
    names = extract_data("name", string)
    prices = extract_data("price", string)
    descriptions = extract_data("description", string)
    calories = extract_data("calories", string)

def display_menu(names, descriptions, calories, prices):
    for i in range(len(names)):
        print(f"{names[i]} - {descriptions[i]} - {calories[i]} - {prices[i]}")

def display_stats(total_items, average_calories, average_price):
    total_items = len(names)
    average_calories = sum(map(int, calories)) / total_items
    average_price = sum([float(price[1:]) for price in prices]) / total_items
    print(f"\n{total_items} items - {average_calories:.1f} average calories - ${average_price:.2f} average price")

def main():
    read_data()
    extract_data(tag, string)
    get_data()
    display_stats(total_items, average_calories, average_price)
    display_menu(names, descriptions, calories, prices)

main()

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education