/ sc06.py
sc06.py
1 import xml.etree.ElementTree as ET 2 3 tree = ET.parse('recipeBox.xml') 4 root = tree.getroot() 5 print(root) 6 7 email = input("Enter your email: ") 8 9 user = None 10 11 for customer in root.findall('customers/customer'): 12 if customer.find('email').text == email: 13 user = customer 14 break 15 16 if user is None: 17 raise ValueError("User not found") 18 19 print(f"\nWelcome {user.find('name').text}! Here are the available menus:\n") 20 21 # for each menu, print the name attribute 22 for i, menu in enumerate(root.findall('menus/menu')): 23 print(f"{i+1}. {menu.get('name')}") 24 # for each menu, print the recipes 25 for meal in menu.findall('meal'): 26 recipe = root.find(f"recipes/recipe[@id='{meal.get('recipeId')}']") 27 print(f" - {recipe.find('title').text}") 28 29 print() 30 31 print("Which menu would you like to order?\n") 32 33 menu = int(input("Enter the number of the menu: ")) 34 35 if menu < 1 or menu > len(root.findall('menus/menu')): 36 raise ValueError("Invalid menu number") 37 38 menu = root.findall('menus/menu')[menu-1] 39 40 print(f"\nYou have selected the {menu.get('name')} menu. Here are the recipes:\n") 41 42 for meal in menu.findall('meal'): 43 recipe = root.find(f"recipes/recipe[@id='{meal.get('recipeId')}']") 44 print(f" - {recipe.find('title').text}") 45 46 print("\nWhich deliveryPerson would you like to deliver your order?\n") 47 48 for i, deliveryPerson in enumerate(root.findall('deliveryPeople/deliveryPerson')): 49 print(f"{i+1}. {deliveryPerson.find('name').text}") 50 51 print() 52 deliveryPerson = int(input("Enter the number of the deliveryPerson: ")) 53 54 if deliveryPerson < 1 or deliveryPerson > len(root.findall('deliveryPeople/deliveryPerson')): 55 raise ValueError("Invalid deliveryPerson number") 56 57 deliveryPerson = root.findall('deliveryPeople/deliveryPerson')[deliveryPerson-1] 58 59 print(f"\nYou have selected {deliveryPerson.find('name').text} to deliver your order.") 60 61 print("\nOrder Confirmation:\n") 62 print(f"Menu: {menu.get('name')}") 63 for meal in menu.findall('meal'): 64 recipe = root.find(f"recipes/recipe[@id='{meal.get('recipeId')}']") 65 print(f" - {recipe.find('title').text}") 66 67 print(f"Delivery Person: {deliveryPerson.find('name').text}") 68 print(f"Delivery Address: {user.find('address').text}") 69 70 confirmation = input("\nDo you confirm your order? (yes/no): ") 71 72 if confirmation.lower() in ['yes', 'y']: 73 print("\nYour order has been confirmed. Thank you!") 74 else: 75 print("\nYour order has been cancelled. Thank you!") 76 77 print(f"\nYour order is on its way! You can contact {deliveryPerson.find('name').text} at {deliveryPerson.find('phone').text} for any questions.")