Проверить ввод пользователя и передать значение в основную функцию в Python? - PullRequest
0 голосов
/ 31 октября 2019
#Main function
def main():
    menu()
    take_order()
    pass
#show menu
menuL = []
def menu():
    print("Hi welcome to X Burger Club \nOur menu:")
    one =print("1.X Burger","{:>10}".format("$5.25"))
    two =print("2.Bacon Cheese", "{:>12}".format("$5.75"))
    three =print("3.Mushroom Swiss", "{:>10}".format("$5.95"))
    four =print("4.Western Burger", "{:>10}".format("$5.95"))
    five =print("5.Don Cali Burger", "{:>9}".format("$5.95"))
    six =print("6.Sorry,I'm not going to order today")
    menuL = [one,two,three,four,five,six]
    return menuL,six
#ask user for order - take input
# in take_order we need to return the quantity and the price
def take_order(order,amount):
    flag = True
    while flag:
        try:
            order = input('What can I get for you today?')
            while order in menuL:
                amount = int(input("How many would you like?"))
        except:
            print("Print enter positive number")
    return amount,order
def pay_cal(amount,price):
    pay = amount * price
    pass



main()

У меня вопрос: как связать соединение между меню в функции меню с функцией take_order (), и в то же время создать цикл, который работает непрерывно, пока пользователь не выберет опцию 6 вменю, которое выйдет из функции, и после проверки ввода программа примет количество и цену в меню, чтобы передать их в функцию pay_cal () для вычисления итоговой суммы. моя идея состоит в том, чтобы создать список

menuL = []
#this list store all the menu option

, но мне трудно понять, как работают передаваемые аргументы и значения.

def take_order(order,amount):
    flag = True
# I try to use while loop with true to continuously run the loop until the user choose option 6 - exit
# since the variable 6 in the local function, how do I compare the string? 
    while flag:
        try:
            order = input('What can I get for you today?')
            while order in menuL:
#This step I try to take the quantity.
                amount = int(input("How many would you like?"))
        except:
            print("Print enter positive number")
    return amount,order

Это мой первый курс программирования, но у меня естьтрудно понять передаваемые аргументы в функции. Основная идея в том, что я пытаюсь создать меню для ресторана, после того, как возьму заказ и сумму, я вычислю оплату и передам все в основную функцию. Спасибо за вашу помощь !!

...