-1

This is part of (emphasis on part of) a simple text based adventure that i am making right now. For some reason every time i run this and say "no" at either point it still goes ahead and executes the code for "yes". Feel free also to suggest any ways to clean up this code. I self teach using the internet and are very new to python so no hate please :).

if path1 == "1":
while breakhold3 == 0:
    if path1 == "1":
        poi1 = raw_input ("There is a strange artificial hole in the ground. It is surrounded by yellow bricks and vines cover them. Would you like to investigate?")
        if poi1 == "Yes" or "yes" or "ye" or "Ye" or "Y" or "y":
            print("You crouch down to look in the hole. When you look in, you find that it goes so deep all you can see is blackness. There is a large rock next to the hole.")
            if item == "1":
                poic1 = raw_input ("You get out the rope and attatch it to the rock. You throw it down the hole and it is at least 2 seconds before you hear it hit the bottom. Would you like to descend the rope?")
                if poic1 == "Yes" or "yes" or "Ye" or "ye" or "Y" or "y":
                    print ("You slowly descend down the rope. It takes about a minute before you get to the bottom. It is dark here, and you begin to feel around the room with your hands.") 
                    from random import randrange
                    numberboy = randrange(7,10)
                    if numberboy == 7:
                        print ("You unluckily fall into a pit!")
                        health -= 1
                        if health == 0:
                            print ("You drop to your knees and lie, filled with pain in the pit. You drop to the floor. Your quest is over.")
                        print ("Your health has fallen to " + str(health) + ". ")
                    if numberboy in (8,9):
                        print ("You could have fallen into a pit but you luckily didn't!")

                    print ("You find a path leading of to another room.")

                    print ("You walk down the path and find a light illuminating an elvish sword!")
                    print ("You walk out of an escape path and find youself coming out of a secret entrance at the clearing.")
                    breakhold3 += 1
                    break
                if poic1 == "No" or "no" or "n" or "N":
                    print ("You decide not to descend down the rope. You continue down the path ahead.")
                    breakhold3 += 1
        if poi1 == "no" or "No" or "n" or "N":
            print ("You decide not to investigate. You continue down the path ahead.")
            breakhold3 += 1

print ("Check")
import time

NOTE: i did breakhold 3 = 0 earlier on.

Lixerman99
  • 151
  • 1
  • 2
  • 11

2 Answers2

3

The problem is with this type of boolean expression:

if poi1 == "Yes" or "yes" or "ye" or "Ye" or "Y" or "y":

This is what you were trying to do:

if poi1 == "Yes" or poi1 == "yes" or poi1 == "ye" or poi1 == "Ye" or poi1 == "Y" or poi1 == "y":

The problem was that those strings evaluate to True by themselves.

A better solution might be to check if poi1 is in a list of "yes" values:

if poi1.lower() in ["yes", "ye", "y"]:

Simpler, yet:

if poi1.lower().startswith("y"):

Also, remember that you have those incorrect boolean expressions in several places in your code that you posted.

huderlem
  • 251
  • 1
  • 5
0

Alternatively, try a language specifically suited to text adventures:

http://inform7.com

http://tads.org

More at http://www.ifwiki.org

David Cornelson
  • 391
  • 2
  • 3
  • 16