Home > Learning, Lesson, Problem, Projects/Experiments, Python > Python: Orders Manager P2

Python: Orders Manager P2

Orders Managment System
Subject: Main Menu and creation of the data file – P2

First thing we will talk about the menu, in this post we will cover the Main Menu and the user choice. Also we will add some validation.

Main Menu: Here is a list of what we will have in the main menu with some descriptions for each choice.
Load File: We will name the file as “orders_data.csv” so once we start the application the system will check if the file exist or not, if Yes then the application will load it automatically as DataFrame (df) if not thats mean you are running the app for the first time, so we will go through file creating process.

Show Data: In this option we will have another sub menu page having:
1. Show all data.
2. Show sample data.
3. Show last 5 records.

Sort: Here we will have sorting as columns that we have, the user will select a column.

Search: We can here search for an order by Date, Price, Quantity or details, also we will do groping for the data.
Missing Data: To show us how many missing data we have so we can fill them.
Add New Order: To add new order to the system.
Edit a Record: To Edit/change a record.
Delete a Record: To delete a record from the DataFrame.
Save: To save what ever you do to the DataFrame.

The Main Menu

def the_menu ():

print(‘\n ::—–{ The menu }—-::’)

print(‘1. Create New csv File’)

print(‘2. Show Data’)

print(‘3. Sort.’)

print(‘4. Search.’)

print(‘5. Missing Data’)

print(‘6. Add New Record.’)

print(‘7. Edit a record.’)

print(‘8. Delete a Record.’)

print(’9. Save the File.’)

return input(‘\n Select from the menu (”q” to quit): ‘)

Main while loop: In the application body we will use a while loop to control the user input and run the function he select. Unlike what we did In the zoo managment system, we will add a validation on the user input as:

1. If the user enter any thing else than numbers (1 to 9) or ([q – Q] for quit) nothing will happen.
2. If the user select (q to quit) then we will ask if he want to save before Exit.

Here is the code …

Main while loop
# calling the menu
user_enter = the_menu()

Validation: If the user enter any thing else than numbers
or (q for quit) nothing will happen.
while user_enter !=’q’ or ‘Q’ :

if user_enter in [‘q’,’Q’] :

print(‘\n You select to Exit the application.’)

save_it = input(‘\n Do your want to save your work/changes [y or n] ? ‘)

if save_it in [‘y’,’Y’]:

save_the_df (df)


elif user_enter not in [‘1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9’] :

user_enter = the_menu()



user_enter = the_menu()

Here is a screen shot for the code..

In this post we cover the Main Menu and the main while loop we need to call the functions, in the coming post we will create the data file and Adding new record.

Follow me on Twitter..

  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: