import json import random products = "products.json" categories = "categories.json" def findthesnacks(products): """these are the snacks you are looking for""" with open(products, 'r') as snacks: snackdata = json.load(snacks) return random.choice(snackdata) def munchies(amount): snack_menu = [] for _ in range(amount): snack_menu.append(findthesnacks(products)) return snack_menu def findthecategory(snack): snack_category = snack["categorie"][0] with open(categories, 'r') as category_json: categorydata = json.load(category_json) for category in categorydata: if category["cat_code"] == snack_category: return category["cat_name"] def has_snack_image(snack): return "img_url" in snack def menu(): snack_menu = munchies(3) menu = "" for snack in snack_menu: snack_title = snack["title"] snack_price = snack["price"] snack_category = findthecategory(snack) happy_snack_image = has_snack_image(snack) menu += f"Have you tried {snack_title} from the menu section {snack_category} for the price of {snack_price} euros" if happy_snack_image: menu += "\r\n" snack_img = snack["img_url"] menu += f"[An image of {snack_title}]({snack_img})" menu += "\r\n" return menu print(menu())