Python3.6.6输入不从inpu返回任何内容

2024-10-06 16:17:18 发布

您现在位置:Python中文网/ 问答频道 /正文

目前我的代码非常简单

#BlackJack

print("welcome to Wasteful's blackjack game")`
print("this program was built using standard python")

print("please select a option")
print("A to start, B to quit")
print("----------------------------")

menu_select = input("A/B: ").lower

if menu_select == "a":
    print("starting game when i can be assed to program it")
elif menu_select == "b":
    exit()
else:
    print("invalid")

但是ab都返回空白?我被困住了,需要一些帮助,谢谢

编辑:我注意到了.lower中的愚蠢错误,应该是.lower()


Tags: to代码gamethisprogramselectlowermenu
2条回答
def main():
    print("welcome to Wasteful's blackjack game") 
    print("this program was built using standard python")
    print("please select a option") 
    print("A to start, B to quit")
    print("              ")
    menu_select = input("A/B: ").lower()

    if (menu_select == "a"):
        print("starting game when i can be assed to program it") 

    elif (menu_select == "b"):
        exit() 

    else: 
        print("invalid")

main()

首先,正如rassar所说,您必须在从用户获得输入后调用.lower()。 下一步,我总是发现创建一个主循环函数来调用所有未来的函数更容易,并且代码保持整洁!希望这有点帮助! 快乐编码!:)

这是因为您没有调用lower(),而是将menu_select设置为函数本身

>>> menu_select = input("? ").lower
? 
>>> menu_select
<built-in method lower of str object at 0x10ca5eab0>

将您的线路改为:

menu_select = input("A/B: ").lower()

相关问题 更多 >