2013-09-25 213 views
-5
from sys import exit 

def gold_room(): 
    print "This room is full of gold. How much do you take?" 

    next = raw_input(">") 
    if "0" in next or "1" in next: 
     how_much = int(next) 
    else: 
     dead("Man, learn to type a number.") 

    if how_much < 50: 
     print "Nice, you're not greedy, you win!" 
     exit(0) 
    else: 

    dead("You greedy bastard!") 


def bear_room():  
    print "There is a bear here."  
    print "The bear has a bunch of honey."  
    print "The fat bear is in front of another door." 
    print "How are you going to move the bear?"  
    bear_moved = False 

    while True: 
     next = raw_input("> ") 

     if next == "take honey":  
      dead("The bear looks at you then slaps your face off.")  
     elif next == "taunt bear" and not bear_moved: 
      print "The bear has moved from the door. You can go through it now." 
      bear_moved = True 
     elif next == "taunt bear" and bear_moved: 
      dead("The bear gets pissed of and chews your legs off.") 
     elif next == "open door" and bear_moved: 
      gold_room() 
     else: 
      print "I got no idea what that means." 


def cthulhu_room(): 
    print "Here you see the great evil Cthulhu." 
    print "He, it, whatever stares at you and you go insane." 
    print "Do you flee for your life or eat your head(flee/head)?" 

    next = raw_input("> ") 

    if next == "flee": 
     start() 
    elif "head" in next: 
     dead("Well that was tasty!") 
    else: 
     cthulhu_room() 

def dead(why): 
    print why, "Good job!" 
    exit(0) 


def dog_room(): 
    print "you entered a room and you see a dog sleeping and the door behind you got locked by it self" 
    print "you see a sign that says this dog got a very good hearing sense, above a normals dog hearing sense." 
    print "and you see a spear beneath you." 
    print "and you can see that there is a bridge behind him." 
    print "what will you do now?try to go to the bridge, pick up the spear, try to sneak your way to the dog and hit him or attack the door." 
    print "(bridge/spear/sneak and hit/attack the door)" 

    spear = False 

    while True: 

     action = raw_input("Choose what you want to do") 
     if action == "bridge" and not spear: 
      death("the dog woke up rushed to you and ate you right after he ate your balls." 
     elif action == "sneak and attack" and not spear: 
      death("you sneaked your way to the dog, hit him, and the damage you made to him wasn't strong enough and he ate you right after he ate your ball.") 
     elif action == "spear" and not spear: 
      spear = True 
      print "you took the spear. what now?" 
     elif action == "spear" and spear 
      print "you already took the spear..." 
     elif action == "sneak and attack" and spear: 
      golden_room("you stabbed the dog and went across the safe bridge with no casualties and you managed to get to the golden room!!!!!!!!") 
     elif action == "attack the door": 
      print "you broke the wooden door, the dog woke up, rushed to you, you tried to escape but the dog was faster" 
      print "and ate you right after he ate your balls." 
      death() 
     else: 
      print "*face palm* come on learn how to type!" 

def start(): 
    print "You are in a dark room." 
    print "There is a door to your right and left." 
    print "Which one do you take(left/right/forward)?" 

    next = raw_input("> ") 

    if next == "left": 
     bear_room() 
    elif next == "right": 
     cthulhu_room() 
    elif next = "forward": 
     dog_room() 
    else: 
     dead("You stumble around the room until you starve.") 


start() 
现在

的问题 当我在电源外壳运行它:无效Python语法

>>>python ex35.py 
what i get is: 
File "ex35.py", line 77 
    elif action == "sneak and attack" and not spear: 
    ^

SyntaxError: invalid syntax 

HELP!我试图找出一小时,一小时和三十分钟。 ty 如果您在查找 时遇到问题,它位于位于dog_room() 函数内部的while循环内的if行 的正下方。

+4

缺少':'在这条线:'ELIF动作==“矛”和矛' –

+0

修复你的代码的格式。 –

+1

@hcwhsa:不行,早些时候它缺少''''。 – geoffspear

回答

3

缺少结束括号:

death("the dog woke up rushed to you and ate you right after he ate your balls." 

缺少尾随冒号:

elif action == "spear" and spear 
+0

这导致'elif'行上出现'SyntaxError'的原因是缺少关闭')'表示下一行正在继续函数调用,这意味着它必须以逗号后跟一个表达式开头,而不是' elif'声明。 – abarnert

+0

我修正了你的缩进。虽然这可能是他在这个问题上的水平,但将它放在你的答案中看起来很糟糕。除此之外,很好的答案(+1)。 – iCodez

0
death("the dog woke up rushed to you and ate you right after he ate your balls." 
--------------------------------------------------------------------------------^ 

你缺少一个右括号)

+0

谢谢大家的帮助:) 我发现错误太多 1)最后一行之前6行:elif next =“forward”:需要加“=” 2)此行后面2行^:else: 有一个标签空间而不是4个普通空间。 – bill