【问题标题】:Why "While" doesn't show anything after input command? [duplicate]为什么“While”在输入命令后不显示任何内容? [复制]
【发布时间】:2019-10-28 22:06:29
【问题描述】:

我认为我在 while 循环中做错了什么

在打印菜单部分后你可以输入一些东西但程序结束。

print("Welcome in American Roulette")
rules=("blabla rules of roulette")
import random


while True:
    print("Enter 'rules' to show rules")
    print("Enter 'play' to play the game")
    print("Enter 'author' to show info about creator")
    print("Enter 'quit' to end the program")
    user_input=input()
    if user_input=="quit" or "Quit":
        break
    elif user_input=="rules" or "rule" or "Rules" or "Rule":
        print(rules)
    elif user_input=="play":
        bet=int(input("Place your bet\n"))
        amount=float(input("How much you want to bet?"))
        spin=random.randint(0,36)
        if bet>36:
            print("You need to bet number beetwen 0 and 36!")
        elif bet<0:
            print("You need to bet number beetwen 0 and 36")
        elif spin==bet:
            print("You won",amount*35)
            print("Now you have",start-amount+amount*35)
        else:
            print("You lose")
    elif user_input=="author":
        print("Jacob X")
    else:
        print("Unknown command")

这里添加了一些文字,因为我的代码主要是代码 ffs

【问题讨论】:

    标签: python random while-loop


    【解决方案1】:

    您的第一个if 应该是:

    if user_input.lower() == "quit":
        break
    

    if user_input == "quit" or user_input == "Quit":
        break
    

    您缺少条件中的第二个user_input。由于"Quit" 不是一个空字符串,它的计算结果为True,你的while 循环将中断。

    这个elif也是这样:

    elif user_input=="rules" or "rule" or "Rules" or "Rule":
    

    【讨论】:

    • 感谢您提供有用且快速的回答,现在正在工作
    猜你喜欢
    • 1970-01-01
    • 2020-05-23
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多