Python Forum
Interactive Menu, String Search?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interactive Menu, String Search?
#1
Hi everyone, I'm just starting my journey with Python.
Here is something I'm working on today. It is an interactive restaurant menu.
I'm able to get it to run with no errors/exceptions. There is a part of the program to have the guest
input an item to the menu. For some reason, this item is added but can't be ordered.
Everything else seems to work.


menu = "salad, pasta, sandwich, pizza, drinks, dessert "
print("Our menu is:", menu)

menu2 = input("Would you like to add something to the menu?")

menu3 = menu + menu2

print(menu3)

menu_ask = input("What would you like from the menu?") 

if menu_ask.casefold() in menu3:
	print("Yes, we have ", menu_ask, " tonight.")
else:
	print("Sorry, we don't have ", menu_ask, " tonight.") 


Here is an example of the output:

Our menu is: salad, pasta, sandwich, pizza, drinks, dessert
Would you like to add something to the menu? Pie
salad, pasta, sandwich, pizza, drinks, dessert Pie
What would you like from the menu? Pie
Sorry, we don't have Pie tonight.

I actually just got it to work. I had some lines of code commented out that I removed and now it works.

Now it's not working. Driving me nuts.

if menu_ask.casefold() in menu3.casefold():
This solved it.
Reply
#2
After the crash some of my post are missing and seeing that maggotspawn has said that the code is working that was posted, I'm going to post my version of the solution.
Maybe it will help someone in the future

#! /usr/bin/env python3.8
'''Docstring'''
import sys
menu = ['salad', 'pasta', 'sandwich', 'pizza', 'drink', 'dessert']

print(f'Our Menu: {", ".join(menu).title()}')

ask = input('Would you like to add a menu item? y or n : ')
if ask == 'y':
    print()
    extra = input('What item would you like to add?: ')
    menu.append(extra)
else:
    pass
print()
print(f'Our Menu: {", ".join(menu).title()}')
order = input('What would you like from the menu? Seperate multiple items with a comma\n : ').split(',')

print('\nYour order:\n')
for item in order:
    if item.strip().casefold() in '\n'.join(menu).casefold():
        if item == '':
            print('You did not order anything.')
            sys.exit()
        else:
            print(f'{item.title().strip()} is on the menu')
    else:
        print(f'Sorry, {item.title()} is not on the menu.')

print()
Output:
Our Menu: Salad, Pasta, Sandwich, Pizza, Drink, Dessert Would you like to add a menu item? y or n : y What item would you like to add?: cherry pie Our Menu: Salad, Pasta, Sandwich, Pizza, Drink, Dessert, Cherry Pie What would you like from the menu? Seperate multiple items with a comma : salad, pizza, cherry pie, coke Your order: Salad is on the menu Pizza is on the menu Cherry Pie is on the menu Sorry, Coke is not on the menu.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
Nicely done menator01. Makes my code look barbaric in comparison. Yours is case sensitive though.
Reply
#4
Going to post one more example. This does not have the add item. Uses terminal colors.
I was going to post the output but, I could not do it in color so, I didn't.
#! /usr/bin/env python3.8
'''Docstring'''

import sys
import os


class FastFood:
    def __init__(self):
        self.menu_items = ['hamburger', 'cheese burger', 'fries', \
        'coke', 'coffee', 'tea', 'milkshake']

    def menu(self):
        return f'Menu: {", ".join(self.menu_items).title()}'

    def order(self):
        on_menu = []
        not_on_menu = []
        return_values = []

        os.system('clear')

        old_string = (f'\nOur Menu: \033[96m{", ".join(self.menu_items)}\033[00m')
        new_string = old_string.replace(',', '\033[00m,\033[96m')
        print(f'{new_string}\n')
        self.order_items = \
        input('Can I take your order?\n\033[93mSeperate multiple items with a comma.\033[00m\n: ').split(',')

        for item in self.order_items:
            if not item.strip():
                os.system('clear')
                print(f'\n\033[91m You did not order anything.\033[00m')
                sys.exit()
            if item.strip().casefold() in '\n'.join(self.menu_items).casefold():
                on_menu.append(item.strip())

            else:
                not_on_menu.append(item.strip())

        os.system('clear')
        if on_menu:
            old_string = (f'\nYour Order: \033[93m{", ".join(on_menu).title()}\033[00m')
            new_string = old_string.replace(',', '\033[00m,\033[93m')
            print(f'{new_string}')

        if not_on_menu:
            old_string = \
            (f'\nSorry, \033[91m{", ".join(not_on_menu).title()}\033[00m is not on the menu.')
            new_string = old_string.replace(',', '\033[00m,\033[91m')
            print(f'{new_string}\n')

        print()

food = FastFood()
food.order()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Writing a Linear Search algorithm - malformed string representation Drone4four 10 833 Jan-10-2024, 08:39 AM
Last Post: gulshan212
  Interactive plots that can be embed in web page mouse9095 1 571 Jun-12-2023, 04:51 PM
Last Post: deanhystad
  Search multiple CSV files for a string or strings cubangt 7 7,842 Feb-23-2022, 12:53 AM
Last Post: Pedroski55
  Search string in mutliple .gz files SARAOOF 10 6,777 Aug-26-2021, 01:47 PM
Last Post: SARAOOF
  fuzzywuzzy search string in text file marfer 9 4,433 Aug-03-2021, 02:41 AM
Last Post: deanhystad
  I want to search a variable for a string D90 lostbit 3 2,585 Mar-31-2021, 07:14 PM
Last Post: lostbit
  interactive map and function hurc60248 1 1,722 Jan-08-2021, 09:22 PM
Last Post: Larz60+
  how to pass the interactive string to Popen subprocess maiya 1 1,846 Sep-18-2020, 09:36 PM
Last Post: Larz60+
  String search in different excel Kristenl2784 0 1,679 Jul-20-2020, 02:37 PM
Last Post: Kristenl2784
  for / else not working in interactive mode Skaperen 4 2,504 Jul-17-2019, 06:16 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020