This is a Python Menu Ordering System using functions, loops and data structures, f strings, padding strings using formatting specifier (:).
-
Python 3.11 and above — Follow this link to download Python for your operating system. You can refer to these tutorials on YouTube for the same — Windows, Mac-OS, Ubuntu (it’ll be somewhat similar for other Linux distributions).
-
pip — pip has been included with the Python installer since versions 3.4 for Python 3 and 2.7.
-
Install pipenv using pip — pip install pipenv
- Install required dependencies using pipenv — pipenv install
- Activate Python Virtual Environment — pipenv shell
- Run the program — python main.py
- Github: Code
- Python Functions
- Python Loops
- Python List Comprehensions
- Python Data Structures
- Python f strings
- Padding strings using formatting specifier (:)
Here is a code snippet:
menu = {
1: {'name': 'espresso',
'price': 1.99},
2: {'name': 'coffee',
'price': 2.50},
3: {'name': 'cake',
'price': 2.79},
4: {'name': 'soup',
'price': 4.50},
5: {'name': 'sandwich',
'price': 4.99}
}
# DISPLAY MENU
def display_menu():
print('------- Menu -------')
for selection in menu:
# pads the output string of menu[selection]['name'] to a width of 9 characters, aligning it to the left of that space.
# pads the output string of menu[selection]['price'] to a width of 5 characters, aligning it to the right of that space.
print(
f"{selection}. {menu[selection]['name'] : <9} | {menu[selection]['price'] : >5}")
print()
# TAKE ORDER
def take_order():
display_menu()
order = []
count = 1
for i in range(3):
item = input(f'Select menu item number {count} (from 1 to 5): ')
count += 1
order.append(menu[int(item)])
return order
# PRINT ORDER
def print_order(order):
print('\n')
print('You have ordered ' + str(len(order)) + ' items')
items = []
items = [item['name'] for item in order]
print(items)
return order
- W3Schools Python Tutorial - This helped me use python functions, loops and data structures, f strings, padding strings using formatting specifier (:)
- Pipenv Setup - This helped me setup my python virtual env
- Website - Marvin Morales Pacis
- LinkedIn - @marventures
- Twitter - @marventures11