python 3.6.6输入未从输入返回任何内容

时间:2019-01-12 23:09:14

标签: python python-3.x

目前我的代码非常简单

export

但是对于#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") a都返回空白吗?我被困住了,可能需要一点帮助,谢谢!

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

2 个答案:

答案 0 :(得分:0)

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

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

将行更改为:

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

答案 1 :(得分:0)

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()。 接下来,我总是发现创建一个主循环函数来调用所有将来的函数并使代码保持整洁更容易!希望这有所帮助! 编码愉快! :)