Python Forum
Interactive Menu, String Search?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interactive Menu, String Search?
#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


Messages In This Thread
Interactive Menu, String Search? - by maggotspawn - May-10-2020, 11:07 PM
RE: Interactive Menu, String Search? - by menator01 - May-11-2020, 12:41 PM
RE: Interactive Menu, String Search? - by menator01 - May-11-2020, 05:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Writing a Linear Search algorithm - malformed string representation Drone4four 10 1,213 Jan-10-2024, 08:39 AM
Last Post: gulshan212
  Search multiple CSV files for a string or strings cubangt 7 8,428 Feb-23-2022, 12:53 AM
Last Post: Pedroski55
  Search string in mutliple .gz files SARAOOF 10 7,163 Aug-26-2021, 01:47 PM
Last Post: SARAOOF
  fuzzywuzzy search string in text file marfer 9 4,817 Aug-03-2021, 02:41 AM
Last Post: deanhystad
  I want to search a variable for a string D90 lostbit 3 2,724 Mar-31-2021, 07:14 PM
Last Post: lostbit
  interactive map and function hurc60248 1 1,835 Jan-08-2021, 09:22 PM
Last Post: Larz60+
  how to pass the interactive string to Popen subprocess maiya 1 1,949 Sep-18-2020, 09:36 PM
Last Post: Larz60+
  String search in different excel Kristenl2784 0 1,747 Jul-20-2020, 02:37 PM
Last Post: Kristenl2784
  for / else not working in interactive mode Skaperen 4 2,677 Jul-17-2019, 06:16 PM
Last Post: Skaperen
  Re.search misses string end CaptainCsaba 3 3,374 May-25-2019, 01:46 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

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