title: How to disable/restrict a line of code after it has been run? (Python)
body: <p>I'm very new to coding and Python. I'm making a simple "choose your adventure" type game in Python. The whole object of the game is to enter all 4 rooms/doors and acquire all 4 digits of the secret code to enter a locked door, which leads to the treasure. This is what im using to add a digit to the code: </p>
  
  <pre><code>from random import choice
  
  code = range(10)
  my_code = []
  
  def add_code():
      if len(my_code) &lt; 4:
          code_digit = choice(code)
          my_code.append(code_digit)
  </code></pre>
  
  <p>So for every room, I have puzzles and challenges to conquer. If you complete the challenge, I have it run the add_code() function. What I want to avoid is having a user repeatedly go to the same door, complete the same challenge, and add a digit to the list, without even having to open any other door or complete any other challenge. Is there a way to make a certain line of code not run after it has already been ran once? Like, if door 1's challenge was completed and a digit was added to the code, is there a way to not let the user add another digit from door 1's add_code() function?  </p>