为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

元芳怎么了 2021-10-10 13:40:22
我的代码目前非常简单#BlackJackprint("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: ").lowerif menu_select == "a":    print("starting game when i can be assed to program it")elif menu_select == "b":    exit()else:    print("invalid")但它对两者a和b?都返回空白?我被卡住了,可以使用一些帮助,谢谢!编辑:我注意到 .lower 中的愚蠢错误应该是 .lower()
查看完整描述

2 回答

?
精慕HU

TA贡献1845条经验 获得超8个赞

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


查看完整回答
反对 回复 2021-10-10
?
杨__羊羊

TA贡献1943条经验 获得超7个赞

这是因为你不打电话lower(),你设置menu_select的函数本身:


>>> menu_select = input("? ").lower

>>> menu_select

<built-in method lower of str object at 0x10ca5eab0>

将您的线路更改为:


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


查看完整回答
反对 回复 2021-10-10
  • 2 回答
  • 0 关注
  • 172 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号