破坏提示,简单的if语句?(蟒蛇)

Jef*_*ves 2 python if-statement

def prompt():
    x = raw_input('Type a command: ')
    return x


def nexus():
    print 'Welcome to the Nexus,', RANK, '. Are you ready to fight?';
    print 'Battle';
    print 'Statistics';
    print 'Shop';
    command = prompt()
    if command == "Statistics" or "Stats" or "Stat":
        Statistics()
    elif command == "Battle" or "Fight":
        Battle()
    elif command == "Shop" or "Buy" or "Trade":
        Shop()
    else:
        print "I can't understand that..."
        rankcheck()
Run Code Online (Sandbox Code Playgroud)

实际上,应该做的是在输入stat时输入Stat功能,输入Battle时输入Battle功能,输入shop时输入shop功能.然而,我实际上遇到了问题(Duh).当输入任何内容时,它会直接转到Stat函数.我相信这是因为我处理提示的方式.它几乎只看到第一个if语句并呈现它应该的函数.但是,如果我输入Battle,它仍然需要我进行统计.

我是Python的新手,我来这里是为了寻求一些建议.这有什么想法?提前致谢.

Sve*_*ach 7

条件

command == "Statistics" or "Stats" or "Stat"
Run Code Online (Sandbox Code Playgroud)

总是被考虑True.据计算结果为True,如果commandStatistics,还是它的计算结果"Stats".你可能想要

if command in ["Statistics", "Stats", "Stat"]:
    # ...
Run Code Online (Sandbox Code Playgroud)

相反,或更好

command = command.strip().lower()
if command in ["statistics", "stats", "stat"]:
Run Code Online (Sandbox Code Playgroud)

更轻松一点.