Home > Learning, Lesson, Problem, Projects/Experiments, Python > Python: Coffee Consumption – P7

Python: Coffee Consumption – P7


Learning : Python, SQlite3, Dataset, Pandas,
Subject: Create Coffee Consumption Application.

[NOTE: To keep the code as simple as we can, We WILL NOT ADD any user input Varevecations. Assuming that our user will Enter the right inputs.]

[ IF THE IS FIRST TIME DOWNLOADING THE CODE FILE, SELECT OPTION 7 FROM MAIN-MENU TO CREATE THE DATABASE]


In this part (Part-7) of Coffee Consumption App, we will write a Function to display all Records in the data-base in a table on the screen.

Beginning with formating the table header, we will have the following columns: record Id, Date_time, Coffee_name, Coffee_type, coffee_size, customer_Gender and Rank. Here is the code..

print(‘ ‘*6,’ID’,’ ‘*5,’ Date & Time’,’ ‘*3,’ Coffee Name’,’ ‘*4,’Type’,’ ‘*9,’Size’,’ ‘*4,’ Gender’,’ ‘*4,’ Rank’)
print(‘ ‘*4,’-‘*90)

Next we will execute an SQLITE command to fetch all the records. Here is the commands..
c.execute (f”select * from coffee_con where c_id > 1 “)
dataset = c.fetchall()

Also we will using the lookup tables to get the names using the id keys in the coffee_name, coffee_type, coffee_size columns.

Now, Using the for loop to access all the records and print them on the screen. Here is apart of the code ..


print(‘ ‘*6,'{}’.format(data_id),end=””)
print(‘ ‘*(10 – 5),'{}’.format(data_date),end=””)
print(‘ ‘*(21 – 16),'{}’.format(data_name[0]),end=””)
print(‘ ‘*(14 – len(data_name[0])),'{}’.format(data_type[0]),end=””)
print(‘ ‘*(13 – len(data_type[0])),'{}’.format(data_size[0]),end=””)
print(‘ ‘*(13 – len(data_size[0])),'{}’.format(data_sex),end=””)
print(‘ ‘*(12 – 1),'{}’.format(data_rank))

Here is a screen shot of the code..

python project code coffee consumption ali radwani
OutPut Screen
python project code coffee consumption ali radwani



What’s Coming: In Part-8 we will write the Function to Edit the records on the Main Data-Base.


..:: Have Fun with Coding ::.. 🙂


Part 1 Part 2 Part 3 Part 4 Part 5
Part 6 Part 7 Part – Part – Part –


To Download my Python code (.py) files Click-Here



ali radwani ahradwani.com python projects codeFollow me on Twitter..

By: Ali Radwani

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s