Question

In: Computer Science

Create a report that lists all the customers in alphabetical order by last name. The report...

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]))

Solutions

Expert Solution

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.


Related Solutions

Create a report that lists customers with the total value of their orders from the database....
Create a report that lists customers with the total value of their orders from the database. Each row of the table should list the customer name and the total value of all orders. Rows should be in descending order according to the total. Just list the first 5 customers, those with the highest total orders. This part is more complex and, so, can be approached in many ways. You may decide to use simple queries and put the information together...
C++ Programming Consider an input file that lists test participants in alphabetical order and their scores....
C++ Programming Consider an input file that lists test participants in alphabetical order and their scores. Each line has the following format: LastName FirstName score Load the input file into an array of structs, knowing there is a maximum of 50 participants. Output to output.txt the participants with the top 5 scores, in decreasing order of scores. Each output line should have the following format: FirstName,LastName,score Notes: The name of the input file is acquired through standard input. If the...
C++ Programming Consider an input file that lists test participants in alphabetical order and their scores....
C++ Programming Consider an input file that lists test participants in alphabetical order and their scores. Each line has the following format: LastName FirstName score Load the input file into an array of structs, knowing there is a maximum of 50 participants. Output to output.txt the participants with the top 5 scores, in decreasing order of scores. Each output line should have the following format: FirstName,LastName,score Notes: The name of the input file is acquired through standard input. If the...
Create a report that lists each topping and also lists the number of pizzas that used...
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...
In alphabetical order, the six most common last names in the United States in 2018
In alphabetical order, the six most common last names in the United States in 2018 are Brown, Garcia, Johnson, Jones, Smith, and Williams (United States Census Bureau website). Assume that a sample of 50 individuals with one of these last names provided the following data:    Summarize the data by constructing the following: Relative and percent frequency distributions A bar chart A sorted bar chart A pie chart Based on these data, what are the most common last names? Which type of...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
List customer id, customer full name (Last name, full name, state) for those customers that have...
List customer id, customer full name (Last name, full name, state) for those customers that have ordered more than once. List customers (order id, customer id, and customer last name) that had more than 2 -- products in their order. Order your result based on customer id followed by order id SQL SERVER DATABASE
Create a table with two columns. Name the table First Initial _ Last Name (e.g. John...
Create a table with two columns. Name the table First Initial _ Last Name (e.g. John Dow will create table j_dow). You have to audit all DML statements on your table. To do this you write two triggers: 1. To log any DML statements that users might run on this table. The results must be stored in the First Initial _ Last Name _ Log table (e.g. John Dow will create table j_dow_log). The table should have unique event ID,...
The EXACT sequence or order for your report should be as follows: The Company’s Name The...
The EXACT sequence or order for your report should be as follows: The Company’s Name The Company’s Logo The Company’s Mission Statement The Company’s three (3) main competitors The name of the Chairman, the President, the CEO, and the CFO The Stock Symbol and Exchange that it is traded on The company’s recent stock price The number of company employees worldwide The location of the company’s corporate headquarters (city/state only) The company’s yearly sales for 2019 in billions of dollars...
Discover classes for generating a student report card that lists all classes, grades, and the grade...
Discover classes for generating a student report card that lists all classes, grades, and the grade point average for a semester. Create a UML diagram with constructors and methods. Implement the code including Javadoc comments.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT