我的基于文本的游戏的python语法有什么问题?

时间:2014-02-21 05:02:31

标签: python

print "You wake up in a dark room, There is a box of matches in your pocket. What do you do?"
print "#1 Light a match #2 Do nothing"
door = raw_input(">")
if door == "1":
    print "You light a match, In the room there is an axe and a door without a handle. What do you do?"
    print "#1 Grab the axe #2 Punch the door #3 Do nothing"
    axe = raw_input(">")
    if axe == "1":
        print "You grab the axe, What do you do?"
        print "#1 Knock down the door #2 Do nothing"
        end = raw_input(">")
        if end == "1":
            print "You are free! You Win!"
        elif end == "2":
            print"You wait and then the axe slips out of your hand, decapacitating you. You die"
        else:
            print "Ivalid input. Game End"
            raise SystemExit
    elif axe == "2":
        print"Ow, that hurt. What to do now?"
        print "#1 Grab the axe #2 do nothing"
        chop = raw_input(">")
        if chop  == "1":
            print" You grab the axe, What do you do?"
            print "#1 Knock down the door #2 Do nothing"
            end = raw_input(">")
            if end == "1":
                print "You are free! You Win!"
            elif end == "2":
                print"You wait and then the axe slips out of your hand, decapacitating you. You die"
                raise SystemExit
            else:
            print "Ivalid input. Game End"
            raise SystemExit
        elif chop == "2":
            print "You go insane from waiting. Game Over"
            raise SystemExit
        else:
            print "Ivalid input. Game End"
            raise SystemExit    
    elif axe == "3":
        print "You go insane from waiting. Game Over"
        raise SystemExit
    else:
        print "Ivalid input. Game End"
        raise SystemExit    
elif:
    print"Something in the darkness kills you. Game Over"
    raise SystemExit
else:
    print "Ivalid input. Game End"
    raise SystemExit

执行此代码时,出现错误Unexpected indent

1 个答案:

答案 0 :(得分:3)

错误在于您如何定义变量。你到处都在做,但这是一个例子:

def door = raw_input(">")

在Python中,def仅用于定义函数door,是一个字符串,不需要任何东西

door = raw_input(">")

此外,您正在混合制表符和空格。你需要选择一个并坚持下去。这很关键。所有风格指南都说使用四个空格进行缩进。具体来说,除了 25,26,27,29,32, 39

之外,您在每一行都使用了标签

这是您的第一篇帖子,所以我想帮助您,但是当您收到错误时,您需要包含完整追溯。它们提供了至关重要的信息,例如错误所在的行,以及更复杂的代码,执行如何到达该行。


如果您收到更多错误,则需要将其发布在问题中。

欢迎使用Stack Overflow