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>You're super close. You can just initialize an empty list to store the inventory. When someone guesses a key you just append it to the list. Of course we will check to see if the guessed key is already in the inventory, and if it is, we won't add it.</p>

<pre><code>keepGuess = True
correctKey = "red" 
inventory = []

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

    if guess == correctKey:
            print ("You may enter")
            inventory.append(guess)
            keepGuess = False
    else:
        if guess not in inventory:
            inventory.append(guess)
        else:
            print ("You have already added this key to your inventory.")
        print ("Keep guessing")
</code></pre>

<p>Here's a test:</p>

<pre><code>Guess the key to open the door: blue
Keep guessing
Guess the key to open the door: blue
You have already added this key to your inventory.
Keep guessing
Guess the key to open the door: red
You may enter
</code></pre>

python list python-2.7