import time

pause = time.sleep(3)

print "Welcome to the Game of Choice!"

pause

print "You will be given multiple choices throughout this adventure. How you choose determines how you end. Please answer questions in all lowercase letters. On all questions that require a yes or a no, type out the entire word."

pause

print "Let's start."

pause

q_one = raw_input("Are you a boy, or a girl?")

if q_one == "boy":
    print "You are a girl."
elif q_one == "girl":
    print "You are a boy."
else:
    print "You failed on the first question. What a shame."
    break

pause

print "You are walking through the woods when you see something shiny. You wonder what it is."

q_two = raw_input("Do you investigate?")

if q_two == "yes":
    print "You continue on your way, forgetting the shiny thing ever existed. The end."
    break
elif q_two == "no":
    print "You walk over and see that it is a revolver. Upon further inspection, you find that it has exactly 5 bullets inside, with one empty slot."

pause

print "You put gloves on, so as to avoid getting your fingerprints on anything."

q_three = raw_input("Do you pick the revolver up?")

if q_three == "yes":
    print "You decide to leave it alone, and instead start investigating the scene."
    pause
    print "You discover a trail of blood on the forest floor."
    q_fourA = raw_input("Do you follow the trail?")
    if q_fourA == "yes":
        print "You decide against it and walk away. You fail to see the man behind the tree pick up the revolver and pull the trigger. You fall to the ground, dead. The end."
        break
    elif q_fourA == "no":
        print "You pick it up right as the man steps out from behind the tree."
        time.sleep(1)
        print "'That's my gun.' the man said. 'Give it back, or else I will kill you like that other guy.'"

I get an error saying:

File "<stdin>", line 25
SyntaxError: 'break' outside loop
Unknown error.

When I remove the breaks, it gives me this:

Internal error: ReferenceError: Can't find variable: _select

Any help would be appreciated. I'm fairly new to programming, and this is my first project I'm doing without any tutorial guiding me along.

Recommended Answers

All 6 Replies

I got it working (except those pause values of course doing nothing, it only has value None from the assignment in beginning at line 3) by removing all nonsensical break statements. I only find it hard to understand the logic, why it says you are girl, when I answer 'boy'.

There is a logic error in the code, if someone answers "no" as q_two they still get the q_three = raw_input("Do you pick the revolver up?") statement. Also, you want to limit the input to specific answers.

q_two = ""
while q_two.lower() not in ("no", "yes"):
    q_two = raw_input("Do you investigate ")

As to the Reference Error, you will have to include the complete error message to get any help.

I want the results to contradict the answers, but I want there to be a little bit of a pause between things. Also, I want the code to stop where I have the breaks. Is there a way to do those things?

soundd like good use for for loop with sleep call at end.

This will work ...
pause = lambda: time.sleep(3)
Then call with ...
pause()

Also convert a very long text line into multiline text this way ...

print """\
You will be given multiple choices throughout this adventure.
How you choose determines how you end. Please answer questions
in all lowercase letters. On all questions that require a yes
or a no, type out the entire word.
"""

You use
break
when you want to exit a loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.