In: Computer Science
Create a report that lists each topping and also lists the number of pizzas that used that topping. Order the report in decreasing order of number of pizzas. That is, the most popular toppings will be at the top of the report.2 In each row of the table list: the topping name; the price of the topping; the number of pizzas that used the topping; and, the total value of the topping (number of pizzas times topping price). Since some toppings cost more than others, the total values may not be in descending order.3
Format the monetary amounts with two decimal places. Do this by using the fixed point formatting feature of the formatting method you choose. Do not try rounding the values mathematically.
ex. Gamalost 2.00 237 474.00
import sqlite3 class PizzaServices: def __init__(self): self.connection = sqlite3.connect("pizza-190807A.sqlite") def __enter__(self): return self def __exit__(self, exe_type, exc_val, exl_tb): crs = self.connection.cursor() def do_query(self, query, parameters=None): crs = self.connection.cursor() if parameters: crs.execute(query, parameters) else: crs.execute(query) return crs.fetchall() def customer(self): return self.do_query("select * from customer") def invoices_for_customer(self, customer_id): def pizzas_for_invoice(self, invoice_id): """ returns a list of two items: pizza db row and a list of toppings id's for the pizza The pizza db row has pizza id, crust id, sauce id, combination id (None if this is a regular pizza) and invoice id :param invoice_id: :return: """ def crust_for_id(self, crust_id): def sauce_for_id(self, sauce_id): def topping_for_id(self, topping_id): def pizza_for_id(self, pizza_id): def invoice_for_id(self, invoice_id):
with PizzaServices() as cs: cust = cs.customer() cmd1 = ''' select topping.name, topping.price, count(pizzaTopping.pizzaId), count(pizzaTopping.pizzaId) * topping.price from pizzaTopping, topping where pizzaTopping.toppingId = topping.toppingId group by topping.name, topping.price order by count(pizzaTopping.pizzaId) desc ''' resultSet = cs.do_query(cmd1) # capture the result, It is a list of tuples templateH = "{:25} {:15} {:15} {:15}" line = templateH.format("Topping", "Unit Price", "Total Orders", "Total Value") print(line) for row in resultSet: print("{:25} {:<15} {:<15} {:<15}".format(row[0].strip(), row[1], row[2], row[3]))
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.