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...
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...
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.
C# (Thank you in advance) Create an Employee class with five fields: first name, last name,...
C# (Thank you in advance) Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate...
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth...
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth Create a table ‘ClassInfo’ table: ID Class Name Class Description Create a table ‘RegisteredClasses’ table: StudentID ClassID The RegisteredClasses table should have a foreign key relationship to StudentInfo and ClassInfo tables for the respective IDs. Also the IDs in StudentInfo and ClassInfo need to be primary keys. When you submit the file your email should also contain the following SQL Queries: Query to show...
List department name, employee id, and employee name for all employees in department name order. Repeat...
List department name, employee id, and employee name for all employees in department name order. Repeat for department #10 only. List the course ID, course name, section, instructor name, day, time, and room for all course sections. List the course ID, course name, section, student ID, and student name for CRN 1003. Display the list in ascending order of student last and first names. DROP TABLE registration; DROP TABLE sections; DROP TABLE courses; DROP TABLE students; DROP TABLE instructors; CREATE...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT