In: Computer Science
Create a report that lists all the customers in alphabetical order by last name. The report should include first name, last name, and email address of all customers. This report involves getting data from one table.
The three items should be lined up in columns. Use one of the formatting functions available through Python (the % operator or the format function). Don’t use tabs to line up columns, this does not reliably work and is inflexible.1 Even though we won’t need formatting to line up columns in web pages, there are other aspects of formatting that we may still need. It is best to become familiar with one method now.
not sure how to print out the list alphabetically by last name
pizza_service.py
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")
part1.py
from pizza_services import PizzaServices with PizzaServices() as cs: cust = cs.customer() cmd1 = "select FirstName, LastName, Email from customer" resultSet= cs.do_query(cmd1) templateH = "{:15} {:15} {:15}" line = templateH.format("Last Name", "First Name", "email") print(line) for customer_row in resultSet: print('{:15} {:15} {:15}'.format(customer_row[0], customer_row[1], customer_row[2]))
with PizzaServices() as cs: cust = cs.customer() cmd1 = "select LastName, FirstName, Email from customer order by LastName" resultSet = cs.do_query(cmd1) templateH = "{:15} {:15} {:15}" line = templateH.format("Last Name", "First Name", "email") print(line) for customer_row in resultSet: print('{:15} {:15} {:15}'.format(customer_row[0], customer_row[1], customer_row[2]))
************************************************** Keep the selection of column in the same order in which you print them. 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.