0

I'm working on a supermarket chatbot in python for a school project. I believe that t is working for the most part but it seems that when I 'call the aisle functions' down the bottom it isn't working. after choosing an aisle it is always resulting to the fresh produce aisle, regardless of the input you put in. if you know the fix to this please let me know, or if you find any other issues with the code that I haven't realised. thanks

code:

###########
# imports #
###########

import time
from time import sleep
######################
# creating the lists #
######################
fresh_produce = [
    "apples",
    "bananas",
    "watermelon",
    "straberys",
    "carrots",
    "beans",
    "brocoli",
    "tomatos",
]

meat_seafood = [
    "steak",
    "lamb",
    "sausages",
    "beef mince",
    "chicken",
    "salmon",
    "calamari",
]

avalible_bread = [
    "white bread",
    "wholemeal bread",
    "bread rolls" "baguette",
]

avalible_beverages = [
    "juice",
    "softdrink(2l)",
    "cordial",
    "botteled water",
]

avalible_dairy = [
    "fresh milk(2l)",
    "fresh milk(3l)",
    "longlife milk(1l)",
    "margarine",
    "butter",
    "yogurt",
    "sliced cheese",
    "grated cheese",
]

avalible_deli = [
    "ham",
    "salami",
    "frits",
    "proscitto",
    "pepperoni",
]

###########################
# creating the dictonarys #
###########################

fresh_price = {
    "apples": 1,
    "bananas": 1.50,
    "watermelon": 7,
    "straberys": 0.50,
    "carrots": 0.20,
    "beans": 0.5,
    "brocoli": 3,
    "tomatos": 0.70,
}

meat_sea_price = {
    "steak": 7,
    "lamb": 5,
    "sausages": 0.20,
    "beef mince": 7,
    "chicken": 10,
    "salmon": 8,
    "calamari": 2,
}

bread_price = {
    "sliced white bread": 2,
    "sliced wholemeal bread": 2,
    "bread rolls": 3,
    "baguette": 4,
}

beverages_price = {
    "juice": 4,
    "softdrink(2l)": 4.50,
    "cordial": 3,
    "botteled water": 1,
}

dairy_price = {
    "fresh milk(2l)": 2,
    "fresh milk(3l)": 3,
    "longlife milk(2l)": 2,
    "margarine": 3,
    "butter": 3,
    "yogurt": 6,
    "sliced cheese": 2.50,
    "grated cheese": 4,
}

deli_price = {
    "ham": 4,
    "salami": 3,
    "frits": 2,
    "proscitto": 7,
    "pepperoni": 3,
}

price = []
basket = {}

###########
# welcome #
###########
print("welcome to Mega Mart™ ")
print(
    """at any time you can type:
    goto: to change aisle
    basket: to check what you currently have in you basket (including total price)
    leave: to checkout with your current basket
    quit: to leave and not buy anything
    help: to see this info again
"""
)
######################
# choosing the aisle #
######################
def aisle():
    aisle = input(
        """what aisle would you like to go to?
A)fresh produce
B)meat & seafood
C)bread
D)beverages
E)dairy
F)deli

type the name or letter of the aisle """
    )
    aisle = aisle.lower()
    #######################
    # fresh produce aisle #
    #######################

    def fresh_aisle():
        order_fresh = True
        while order_fresh:
            print("here are your options for fresh produce")
            for fresh_ in fresh_produce:
                print(fresh_)
            fresh = input("what would you like to add to basket? ")
            fresh = fresh.lower()
            if fresh in fresh_produce:
                fresh_amount = int(input("how much would you like? "))
                price.append(fresh_price[fresh] * fresh_amount)
                basket.setdefault(fresh, [])
                print(f"{fresh} has been added to basket.")
                break
            if fresh not in fresh_produce:
                print("sorry, that wasn't an option, check your spelling and try again")

    ########################
    # meat & seafood aisle #
    ########################

    def meatsea_aisle():
        order_meat = True
        while order_meat:
            print("here are your options for meat and seafood")
            for meatsea_ in fresh_produce:
                print(meatsea_)
            meat_sea = input("what would you like to add to basket? ")
            meat_sea = meat_sea.lower()
            if meat_sea in meat_seafood:
                meatsea_amount = int(input("how much would you like? "))
                price.append(meat_sea_price[meat_sea] * meatsea_amount)
                basket.setdefault(meat_sea, [])
                print(f"{meat_sea} has been added to basket.")
                break
            if meat_sea not in meat_seafood:
                print("sorry, that wasn't an option, check your spelling and try again")

    ###############
    # bread aisle #
    ###############

    def bread_aisle():
        order_bread = True
        while order_bread:
            print("here are your options for bread")
            for bread_ in avalible_bread:
                print(bread_)
            bread = input("what would you like to add to basket? ")
            bread = bread.lower()
            if bread in avalible_bread:
                bread_amount = int(input("how much would you like? "))
                price.append(bread_price[bread] * bread_amount)
                basket.setdefault(bread, [])
                print(f"{bread} has been added to basket.")
                break
            if bread not in avalible_bread:
                print("sorry, that wasn't an option, check your spelling and try again")

    ###################
    # beverages aisle #
    ###################

    def beverages_aisle():
        order_beverages = True
        while order_beverages:
            print("here are your options for beverages")
            for beverages_ in avalible_beverages:
                print(beverages_)
            beverages = input("what would you like to add to basket? ")
            beverages = beverages.lower()
            if beverages in avalible_beverages:
                beverages_amount = int(input("how much would you like? "))
                price.append(beverages_price[beverages] * beverages_amount)
                basket.setdefault(beverages, [])
                print(f"{beverages} has been added to basket.")
                break
            if beverages not in avalible_beverages:
                print("sorry, that wasn't an option, check your spelling and try again")

    ###############
    # dairy aisle #
    ###############

    def dairy_aisle():
        order_dairy = True
        while order_dairy:
            print("here are your options for dairy")
            for dairy_ in avalible_dairy:
                print(dairy_)
            dairy = input("what would you like to add to basket? ")
            dairy = dairy.lower()
            if dairy in avalible_dairy:
                dairy_amount = int(input("how much would you like? "))
                price.append(dairy_price[dairy] * dairy_amount)
                basket.setdefault(dairy, [])
                print(f"{dairy} has been added to basket.")
                break
            if dairy not in avalible_dairy:
                print("sorry, that wasn't an option, check your spelling and try again")

    ##############
    # deli aisle #
    ##############

    def deli_aisle():
        order_deli = True
        while order_deli:
            print("here are your options for deli")
            for deli_ in avalible_deli:
                print(deli_)
            deli = input("what would you like to add to basket? ")
            deli = deli.lower()
            if deli in avalible_deli:
                deli_amount = int(input("how much would you like? "))
                price.append(deli_price[deli] * deli_amount)
                basket.setdefault(deli, [])
                print(f"{deli} has been added to basket.")
                break
            if deli not in avalible_deli:
                print("sorry, that wasn't an option, check your spelling and try again")

    ############
    # checkout #
    ############
    
    def checkout():
        print(f"\nYour total order price is: ${sum(price)}")
        payment = input("would you like to pay cash or card? ")
        if payment == 'cash' or 'card':
            print('please wait a moment while we process your payment') ; sleep(5)
            print("""thank you for shopping with Mega Mart™ 
have a great day!""")
        else:
            print("sorry that wasnt an option")
            checkout()
    
    ###############################
    # calling the aisle functions #
    ###############################

    if aisle == "a" or "fresh" or "fresh produce" or "produce" or "1" or "a)":
        fresh_aisle()
    if (
        aisle == "b"
        or "b)"
        or "meat"
        or "seafood"
        or "meat and seafood"
        or "seafood and meat"
        or "meat & seafood"
        or "seafood & meat"
        or "meat seafood"
        or "seafood meat"
        or "meat, seafood"
        or "seafood, meat"
        or "2"
    ):
        meatsea_aisle()
    if aisle == "c" or "bread" or "bread aisle" or "3" or "c)":
        bread_aisle()
    if (
        aisle == "d"
        or "beverages"
        or "beverages aisle"
        or "4"
        or "d)"
        or "drinks"
        or "drinks aisle"
    ):
        beverages_aisle()
    if aisle == "e" or "e)" or "5" or "dairy" or "dairy aisle":
        dairy_aisle()
    if aisle == "f" or "f)" or "6" or "deli" or "deli aisle":
        deli_aisle()

    ###########################
    # additional if statments #
    ###########################

    if "goto":
        aisle()
    if "basket":
        print(f"your basket currently has {basket} with a total price of {price}")
    if "leave":
        print("havent set up function yet")
    if "quit":
        quit()
    if "help":
        print(
            """at any time you can type:
    goto: to change aisle
    basket: to check what you currently have in you basket (including total price)
    leave: to checkout with your current basket
    quit: to leave and not buy anything
    help: to see this info again
"""
        )


aisle()
Tom O'Dea
  • 1
  • 2
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Apr 02 '22 at 04:13

0 Answers0