Python Forum
looking for feedback - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: looking for feedback (/thread-41941.html)



looking for feedback - Luckyoz - Apr-12-2024

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~


RE: looking for feedback - deanhystad - Apr-12-2024

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?