Python: Coffee Consumption – P3
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-3) of Coffee Consumption App, we will fill in some code into selected Functions. We will do the following:
- Create Function: Show list.
- Create Function: is_available.
- Create Function: Manager Menu.
- Create Manager Coffee Name Functions: Add, Edit, Delete
So, let’s start with writing the Manager Menu Function and a while loop to take the user selection and trigger the corresponding Function… Here is the Code ..
![]() |
We have two functions to help us in this application, one of them called def show_list(dt,d_id) is to Display the Data we have in the Lookup Tables based on the user selection function. The Function will take two arguments:
dt: data-table (Coffee Name, Coffee Type, Coffee Size)
d_id: id column name, and returning nothing.
Fisrt, let’s look at this Function:
![]() |
The second Function will be used to check if the user selection is available in the database, we will call it def is_available (dt, d_id, check_id) this Function is to check if the passed ID available in the data-set or not. The Function will take three Arguments as:
dt: Data-Table, d_id : Name of id column, check_id : The id we want to search for, and it will Return the data-set. After return, if dataset is empty that’s mean selected id is not available.
Now let’s see the function code..
![]() |
Now we will start writing first three functions to manage the Coffee Name, and will start with Adding New Coffee Name to the lookup Table.
In coming code first we will call the header then show_list(‘coffee_name’,’cn_id’) passing Table Name:’coffee_name’ and id column:’cn_id’ to display the Coffee Names we have on the sccreen. Then we will ask the user to enter the New Name to be added to the database. Here is the Full code..
![]() |
Next we will write the Edit Function, and again after the header and show_list(‘coffee_name’,’cn_id’) we will ask the user to enter the ID of the Coffee Name to be change, here we will do a simple validation on user input. After that we will update the record that the user select. Here is the code..
![]() |
Last Function in this part is to Delete a selected Coffee Name by selection it’s ID, as in the Edit Fnction, the user will select an Id, we will check the availability the will execute the Delete command. Here is the code..
![]() |
What’s Coming: In Part-4 we will do the Follwing:
Writing three Function to Manage the Coffee Type, Functions are: Add New Coffee Type, Edit Coffee Type and Delete a Coffee Type.
..:: Have Fun with Coding ::.. 🙂
Part 1 | Part 2 | Part 3 | Part 4 | Part 5 |
Part 6 | Part – | Part – | Part – | Part – |
To Download my Python code (.py) files Click-Here
By: Ali Radwani
-
August 26, 2021 at 7:06 amPython: Coffee Consumption – P4 | Ali's Photography Space...
-
August 29, 2021 at 7:10 amPython: Coffee Consumption – P5 | Ali's Photography Space...
-
September 5, 2021 at 7:13 amPython: Coffee Consumption – P6 | Ali's Photography Space...
-
September 8, 2021 at 7:10 amPython: Coffee Consumption – P7 | Ali's Photography Space...
-
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...