Python Forum

Full Version: looking for feedback
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Note : its my first program in python (i used to script for roblox games in lua)

menu = {}
menu["sandwich"] = 20;
menu["burger"] = 25;
menu["pizza"] = 30;
menu["steak"] = 30;
menu["pork"] = 25;
menu["chicken"] = 10;

orders = {};
numOfOrders = 0;



def negate_S(word):
    word = list(word);
    totalLetters = len(word);
    if word[totalLetters - 1] == "s":
        word.pop(totalLetters - 1);
        totalLetters -= 1
        
    if word[totalLetters - 1] == "e":
        word.pop(totalLetters - 1);

    newStr = "";
    
    for letter in word:
         newStr += letter;
    return(newStr);
    
    


def keywordSearch(customerInput):
        splitArray = customerInput.split();
        for word in splitArray:
            word = negate_S(word.lower());
            if word in menu:
                return word;
        return;

def getQuantity(customerInput):
    splitArray = customerInput.split();
    for word in splitArray:
        if word.isdigit():
            return word

def checkYesOrNo(string):
    string = string.lower();
    splitArray = string.split();
    for word in splitArray:
        if word == "yes" or word == "yeah":
            return True;
        else:
            return False;
    

    

while True:
    customerInput = str(input("Please Enter your order: "));

    CustomerOrder = keywordSearch(customerInput);

    quantity = getQuantity(customerInput);

    checkOrder = str(input("You want to order " + str(quantity) + " " + CustomerOrder + ("s") + "?" + ": "));

    checkOrder = checkYesOrNo(checkOrder);

    if checkOrder:
       orders[CustomerOrder] = quantity;
       checkOrderAgain = str(input("Do you want anything else: "));
       checkOrderAgain = checkYesOrNo(checkOrderAgain)
       if checkOrderAgain:
           print("===================");
           print("");
           continue;
       else:
           print("");
           print("===================");
           print("");
           print("Your Order: ");
           for orderName, orderQuantity in orders.items():
              print(orderName + "s x" + str(orderQuantity));
           print("");
           print("===================");
           print("Ty for ordering")
           print("===================");
           break;
    else:
        print("Sorry for the error");
        print("===================");
        print("");
        continue;

~Thank you~
There are issues.

To start with, this is Python, not C++. There should be no semicolons in the program at all.

Your function and variable names do not follow Python naming conventions. No capital letters in variable or function names. Be consistent in indenting and vertical spacing. Convention is two vertical spaces between functions. Conventions are documented here: https://peps.python.org/pep-0008/

All functions should have a docstring that describes what it does.
def negate_s(word):
    """Return word without trailing s or es"""
The logic for negate_S() is wrong. Would remove "e" from "the". In same function there is no need to create newStr, just return word.

Create dictionary like this:
menu = {"sandwich": 20, "burger": 25, "pizza": 30}
Your logic for ordering might be all wrong, or maybe your logic is correct, but the ordering is awkward. Can you describe how you want the user to enter their order?
as there are bugs in your scripts you can use any kind of scripts for roblox using the arceus x here is the link to get all the scripts for free through which your desired feature
Link Removed
or you can download the Link Removed to test or execute scripts into the roblox games
or if you are using the roblox scripts you can use the Link Removed that works perfectly for android or PC both