简体   繁体   English

我的 if/else/elif 语句不起作用或我不知道如何使用它

[英]My if/else/elif statement not working or i dont know how to use it

I wanted to make a menu for a restaurant.我想为餐厅制作菜单。 Because I am new, I wanted to make not a-lot of choices so I got a random excuse but thats not my problem right now.因为我是新人,所以我不想做很多选择,所以我随便找了个借口,但这不是我现在的问题。 I just need help as when I do my if/else/elif statement, well either idk how to use it or i just have a mistake in my code pls help... so this is what i have so far:我只需要帮助,就像我在执行 if/else/elif 语句时一样,或者不知道如何使用它,或者我的代码中有错误,请帮助...所以这就是我目前所拥有的:

import sys

def _menu_():
    print('|--------------------------------|')
    print('|Kids menu:                      |')
    print('| Chicken nuggets(G)           3$|')
    print('| Medium size MAC(G)           5$|')
    print('| EXTRA Fries (GF)         +1.50$|')
    print('|*all menu comes with fries*     |')
    print('|G = GLUTEN   GF = GLUTENFREE    |')
    print('|--------------------------------|')

def _menu_COTD():
    print('|--------------------------------|')
    print('|CATCH OF THE DAY:               |')
    print('| Beef tenderloin (grilled)   24$|')
    print('| Grilled salmon,tuna/mayo 12$   |')
    print('| G = GLUTEN   GF = GLUTENFREE   |')
    print('|--------------------------------|')

def _menu_BOTH():
    print('|--------------------------------|')
    print('|Kids menu:                      |')
    print('| Chicken nuggets(G)           3$|')
    print('| Medium size MAC(G)           5$|')
    print('| EXTRA Fries (GF)         +1.50$|')
    print('|*all menu comes with fries*     |')
    print('|G = GLUTEN   GF = GLUTENFREE    |')
    print('|--------------------------------|')
    print('                                  ')
    print('                                  ')
    print('|--------------------------------|')
    print('|CATCH OF THE DAY:               |')
    print('| Beef tenderloin (grilled)   24$|')
    print('| Grilled salmon,tuna/mayo    12$|')
    print('| G = GLUTEN   GF = GLUTENFREE   |')
    print('|--------------------------------|')
    
    



    
print('Owner:')
print ('hello, i am the owner of the restaurant, unfortunately we have been robbed and all our food is gone except for our catch of the day and our kids menu')
print('    ')
print('is it ok or you want to go to another restaurant (knowing that our prices reduced by 75%)')
print('write "yes" if you want to eat here and write "no" to go somewhere else')

menu_choice = input('will you stay?')
if menu_choice == 'yes':
    print('ok great so what will you take?')

    
else:
    print('ok then, enjoy you expensive other restaurant')
    sys.exit()

menu_choice_2 = input('Kids menu, Catch of the day, or both?')

if menu_choice_2 == 'kids menu':
    _menu_
    
if: menu_choice_2 == 'Catch of th day':
    _menu_COTD
    
if: menu_choice_2 == 'Both':
    _menu_BOTH

so when it says menu_choice_2 i basically want to have either _menu_ (the kids menu) _menu_COTD (the catch of the day) and _menu_BOTH (which is both, _menu_ and _menu_COTD . pls help.. i dont know how to fix this... thanks.所以当它说menu_choice_2时,我基本上想要_menu_ (儿童菜单) _menu_COTD (当天的热门)和_menu_BOTH (两者都是, _menu__menu_COTD 。请帮助..我不知道如何解决这个问题......谢谢。

  • Hanter_yt Hanter_yt

There are two errors.有两个错误。

  • First, there are unnecessary colon(:) for the last two if statement.首先,最后两个 if 语句有不必要的冒号(:)。

  • Second, you need a parenthesis to call the function (eg, menu ())二、需要括号来调用function(如menu ())

I just fixed the last part of the code, so that you can call the functions:我刚刚修复了代码的最后一部分,以便您可以调用函数:

if menu_choice_2 == 'kids menu':
    _menu_()

if menu_choice_2 == 'Catch of th day':
    _menu_COTD()

if menu_choice_2 == 'Both':
    _menu_BOTH()

You're gonna have to call your function.您将不得不致电您的 function。 Right now when you write menu , it evaluates to nothing.现在,当您编写menu时,它的评估结果为零。 Instead, write _menu_() and same for other functions too.相反,也可以为其他功能编写_menu_()和相同的内容。 Also you have a typo in your last if statements, remove the colons from in front of if statements此外,您的最后一个 if 语句中有错字,请删除if语句前面的冒号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM