Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looking for feedback
#1
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~
Reply
#2
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?
Luckyoz likes this post
Reply


Forum Jump:

User Panel Messages

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