title: Yes/No prompt in Python3 using strtobool
body: <p>I've been trying to write an elegant [y/n] prompt for scripts that I'll be running over command line. I came across this:</p>
  
  <p><a href="http://mattoc.com/python-yes-no-prompt-cli.html" rel="noreferrer">http://mattoc.com/python-yes-no-prompt-cli.html</a></p>
  
  <p>This is the program I wrote up to test it (it really just involved changing raw_input to input as I'm using Python3):</p>
  
  <pre><code>import sys
  from distutils import strtobool
  
  def prompt(query):
      sys.stdout.write("%s [y/n]: " % query)
      val = input()
      try:
          ret = strtobool(val)
      except ValueError:
          sys.stdout.write("Please answer with y/n")
          return prompt(query)
      return ret
  
  while True:
      if prompt("Would you like to close the program?") == True:
          break
      else:
          continue
  </code></pre>
  
  <p>However, whenever I try to run the code I get the following error:</p>
  
  <pre><code>ImportError: cannot import name strtobool
  </code></pre>
  
  <p>Changing "from distutils import strtobool" to "import distutils" doesn't help, as a NameError is raised:</p>
  
  <pre><code>Would you like to close the program? [y/n]: y
  Traceback (most recent call last):
    File "yes_no.py", line 15, in &lt;module&gt;
      if prompt("Would you like to close the program?") == True:
    File "yes_no.py", line 6, in prompt
      val = input()
    File "&lt;string&gt;", line 1, in &lt;module&gt;
  NameError: name 'y' is not defined
  </code></pre>
  
  <p>How do I go about solving this problem?</p>