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..
![]() |
OutPut Screen ![]() |
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
By: Ali Radwani
-
September 26, 2021 at 7:05 amPython: Coffee Consumption P8 | Ali's Photography Space...
-
September 30, 2021 at 7:12 amPython: Coffee Consumption P9 | Ali's Photography Space...
-
October 11, 2021 at 7:10 amPython: Coffee Consumption P10 | Ali's Photography Space...