+1 (315) 557-6473 

Create a Program to Create Food Menu System in Python Assignment Solution.


Instructions

Objective
Write a program to create food menu system in python language.

Requirements and Specifications

program to create food menu system in python
program to create food menu system in python 1

Source Code

def displayMenu():

"""

This function displays the menu to the user

:return:

"""

print("1) Diplay all the Food Items and Prices")

print("2) Display how manu Food Items exists")

print("3) Display all the Food Items")

print("4) Display all the Food items with prices under $7.50")

print("5) Confirm that a Food Item is an option")

print("6) Look up a specific Food Item's information")

print("7) Add a Food Item and its Price to the available Item options")

print("8) Change a Food Item's Price")

print("9) Remove a Food Item and its Price from the dictionary")

print("10) Remove all Food Items and Prices from the Food Item options")

print("11) Exit the program menu")

def getMenuOption(message, lb, ub):

"""

Gets an user input from lb and ub.

:param message: Message to be displayed when requesting the input

:param lb: lower bound

:param ub: upper bound

:return: The menu option entered (if valid)

"""

while True:

try:

option = input(message)

option = int(option)

if option >= lb and option <= ub:

return option

else:

print(f"Please enter an option between {lb} and {ub}")

except ValueError:

print("Please enter a valid numeric option")

def getItemsAsTuple(dictionary):

"""

This function transforms a dictionary into a list of tuples of (key, value)

:param dictionary: Dictionary

:return: List of tuples

"""

result = list()

for name, price in dictionary.items():

result.append((name, price))

return result

def getFoodItemsLowercase(dictionary):

"""

This function transforms a dictionary into a list of tuples of (key, value)

:param dictionary: Dictionary

:return: List of tuples

"""

result = list()

for name, price in dictionary.items():

result.append(name.lower())

return result

if __name__ == '__main__':

# Create dictionary with items

menu = {

"Single meat hamburger meal": 7.14,

"Double meat hamburger meal": 8.39,

"Bacon Cheeseburger meal": 8.44,

"Junior hamburger meal": 5.04,

"Chicken sandwich meal": 7.74,

"Chicken strip meal": 7.19,

"French fries": 2.39,

"Onion rings": 2.99,

"Soft drink": 2.14

}

# Start program

program_running = True

while program_running:

displayMenu()

option = getMenuOption("Please enter an option: ", 1, 11)

print()

if option == 1: # display all the food items and prices

if len(menu) > 0: # there are items in the menu

for name, price in getItemsAsTuple(menu):

print("{} - ${:.2f}".format(name, price))

else:

print("There are no Food Items in the menu.")

elif option == 2: # Display the number if items in the menu

print(f"There are {len(menu)} items in the menu.")

elif option == 3: # display all the food items (names only)

for name, price in getItemsAsTuple(menu):

print(name)

elif option == 4: # Display all items with price under 7.5

for name, price in getItemsAsTuple(menu):

if price < 7.5:

print("{} - ${:.2f}".format(name, price))

elif option == 5:# Confirm that a food item is an option

name = input("Enter Food Item name: ")

menu_names_lower = getFoodItemsLowercase(menu)

if name.lower() in menu_names_lower:

print("Food Item is valid.")

else:

print("Food Item not found.")

elif option == 6: # look for specific item

name = input("Enter Food Item name: ")

menu_names_lower = getFoodItemsLowercase(menu)

if name.lower() in menu_names_lower:

price = menu_names_lower[name.lower()]

print(print("{} - ${:.2f}".format(name, price)))

else:

print("Food Item not found")

elif option == 7: # add a food item and price

name = input("Enter Food Item name: ")

try:

price = float(input("Enter price: "))

menu[name] = price

print("The following Food Item has been added to the menu: {} - ${:.2f}".format(name, price))

except ValueError:

print("Invalid price.")

elif option == 8: # change a food item's price

name = input("Enter Food Item name: ")

if name in menu:

try:

price = float(input("Enter new price: "))

menu[name] = price

print("The following Food Item has updated: {} - ${:.2f}".format(name, price))

except ValueError:

print("Invalid price.")

else:

print("Food Item not found")

elif option == 9: # remove from menu

name = input("Enter Food Item name: ")

if name in menu:

price = menu[name]

del menu[name]

print("The following Food Item has removed from the menu: {} - ${:.2f}".format(name, price))

else:

print("Food Item not found")

elif option == 10: # remove all

# For this, just clear the dictionary

menu = {}

print("All Food Items have been removed from the menu.")

elif option == 11: # exit

print("Good Bye!")

program_running = False

print()