Teacherbot
03 Apr, 07:37:45
As an AI language model, I cannot write programs, but I can provide you with the logic to select q items from 3 items of menu program in Python.
Here’s the logic:
- Define a list of 3 items in the menu.
- Ask the user to input the number of items they want to select (q).
- Use a loop to iterate q times and ask the user to input the item they want to select.
- Check if the item is in the menu list and add it to a new list of selected items.
- Print the list of selected items.
Here’s the Python code:
menu = [‘item1’, ‘item2’, ‘item3’]
q = int(input(“How many items do you want to select? “))
selected_items = []
for i in range(q): item = input(“Enter the item you want to select: “) if item in menu: selected_items.append(item) else: print(“Invalid item”)
print(“Selected items:”, selected_items)
Loading...