0

I am creating a prison escape and in a specific puzzle, the player is supposed to mutilate a hand, soap the hand, then wash it in order to get access by a scanner in a different room. The first time the player chooses to mutilate the hand, in the inventory it is added as a 'bloody hand', and when the character uses soap to clean the hand, I replace the 'bloody hand' with 'soapy hand' and then after washing it completely I replace from 'soapy hand' to 'hand' in the inventory. My problem is that no matter what I do, if the player decides to mutilate the hand more than once, the inventory keeps adding 'bloody hand' despite the fact that the player already has this in their inventory. I want to prevent from any additional 'bloody hand' to add to the inventory while the player has either 'bloody hand' , 'soapy hand' or 'hand'. I hope I explained this thoroughly enough, and that I may get good feedback that may help me fix this error. I have already tried the (and) and (or) functions, but neither of those worked. Here is my code:

elif choice == "use razor on hand":
    print ("(cut up mutilated guard's hand)")
    if "bloody hand" not in inventory:
        if "razor" in inventory:
            print ("Furrowing your eyebrows as cold sweat trickled down your neck, you took out your razor blade.")
            print ("Slowly placing the fairly sharp tool on the mutilated guard’s wrist, you closed your eyes and felt")
            print ("flesh of the guard start to tear. You finished the deed. The bloody hand was added to your")
            print ("inventory.")
            add_to_inventory("bloody hand")
            print("")
            print ("Inventory: " + str(inventory))
        elif "razor" not in inventory:
            print ("You don't own this item in your inventory.")
    elif "bloody hand" or "soapy hand" or "hand" in inventory:
        print ("You already own this item in your inventory.")
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Jtob
  • 1
  • 1
    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. [Minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. In particular, we shouldn't have to write wrapper code to show the problem and test any solutions we propose. Please put this in a loop and iterate through a list of simulated inputs to show the problem. – Prune Jan 08 '18 at 23:52
  • `elif "bloody hand" in inventory or "soapy hand" in inventory or "hand" in inventory` – aiven Jan 08 '18 at 23:53

3 Answers3

1

You can ask about each item individually:

elif ("bloody hand" in inventory) or ("soapy hand" in inventory) or ("hand" in inventory):
Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
0

If you want to have many puzzles like that, I'd suggest you to make a function like this:

def is_inside(inventory, item_2_check):
    for item in inventory:
        if item_2_check in item:
            return True
    else:
        return False

if not is_inside(inventory, "hand"):
    #Whatever you want to do.

This will return True for "bloody hand", "soapy hand", and "hand". It does work too in the line if is_inside(inventory, "razor")

Jose A. García
  • 888
  • 5
  • 13
0

You want to check whether any item in the inventory is in the set of hand types:

hands = {"bloody hand", "soapy hand", "hand"}

if "bloody hand" not in inventory:
    ...
elif any(item in hands for item in inventory):
    ...
Peter Wood
  • 23,859
  • 5
  • 60
  • 99