×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

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

July 10, 2024
Professor Liam Taylor
Professor Liam
🇦🇺 Australia
Python
Professor Liam Taylor holds a Master's degree in Computer Science from a prominent university in Australia and has completed over 600 assignments related to Python file handling. His expertise includes designing file handling libraries, implementing data serialization techniques, and optimizing file access patterns. Professor Taylor specializes in multimedia file processing, metadata extraction, and developing cross-platform file handling solutions using Python.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
Ensure you understand the dataset thoroughly before starting your machine learning assignment. Visualize the data, check for missing values, and identify patterns or anomalies to guide your model-building process effectively.
News
In 2024, universities have introduced new programming courses focusing on cybersecurity, machine learning, and artificial intelligence to better prepare students for modern IT careers.

Instructions

Objective

Write a Python homework program to create a food menu system using the Python language. The task is to design a program that allows users to view and select various food items from a menu. The program should display a list of available food options and their corresponding prices. Additionally, the user should be able to add selected items to their order and view the total cost. To make it more interactive, consider implementing options for modifying the order, such as removing items or changing quantities. This Python homework will test your understanding of basic programming concepts, such as variables, loops, conditionals, and functions.

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()

Related Samples

Explore a variety of free Python assignment samples showcasing practical applications, from basic algorithms to advanced data manipulation. These samples offer insights into Python's versatility and are valuable for learning and reference purposes.