Adding a check list and remove from list in Python
<p>So the instruction for the assignment is this</p>

<blockquote>
  <p>Print a simple set of instructions which will offer users a choice of
  keys to open a door.</p>
</blockquote>

<p>So the goals that I think will accomplish this is.</p>

<blockquote>
  <p>make an inventory [rainbow keys]</p>
  
  <p>print the inventory ( you have these keys)</p>
  
  <p>ask to guess key that will open the door</p>
  
  <p>it will check the inventory and if it's a <strong>red</strong> key it will print "open"</p>
  
  <p>else will print keep guessing and remove the key from the inventory</p>
</blockquote>

<p>This is what I have so far. I haven't been able to figure out how to add and check the inventory.</p>

<pre><code>keepGuess = True
correctKey = "red" 

while keepGuess:
    guess = raw_input("Guess the key to open the door: ")

    if guess == correctKey:
            print ("You may enter")
            keepGuess = False
    else:

        print ("Keep guessing")
</code></pre>

<p>Thanks for helping me.
Here's the end results </p>

<pre><code>keepGuess = True
correctKey = "blue"
keys = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]

print keys
print

while keepGuess:
    guess = raw_input("Which key will open the door? ")

    if guess == correctKey:
            print ("You may enter")
            keepGuess = False
    else:
        if guess in keys != "blue":
            keys.remove(guess)
            if guess  not in keys:
                print
                print ("The key didn't open the door.")
                print ("Keep guessing")
                print
                print keys
                print
</code></pre>

<p>Which prints out this</p>

<pre><code>['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']

Which key will open the door? red

The key didn't open the door.
Keep guessing

['orange', 'yellow', 'green', 'blue', 'indigo', 'violet']

Which key will open the door? red
Which key will open the door? blue
You may enter
</code></pre>

<p>Without having more information about your error checking, I can't be sure I'm solving the problem.  However, I would think that you want to maintain a simple list of keys, such as:</p>

<pre><code>door_key_inv = ["red", "yellow", "paisley-print chartreuse"]
</code></pre>

<p>You start the list as <strong>[]</strong> (i.e. empty) and add keys as they're found.</p>

<p>Now, when the user enters a guess, you have to make two checks:</p>

<ol>
<li><p>Is this key colour in inventory?  If so, go to step 2; if not, print a warning.</p>

<p><strong>if guess in door_key_inv:</strong></p></li>
<li><p>Is this the correct key?  If so, open the door and break the loop</p></li>
<li>Loop back to get the next guess.</li>
</ol>

<p>Is that what you needed?</p>

python list python-2.7