code: def ask_yesno(query, default=None):
      
      if default is None:
          default_q = ' [y/n]'
      elif default is True:
          default_q = ' [Y/n]'
      elif default is False:
          default_q = ' [y/N]'
      if sys.version_info[0] == 3:
          inp = raw_input("{query}{default_q} ".format(
              query=query, default_q=default_q)).strip()
      else:
          inp = raw_input("{query}{default_q} ".format(
              query=query, default_q=default_q).encode('utf-8')).strip()
      if inp:
          return inp.lower().startswith('y')
      elif default is not None:
          return default
      else:
          # Loop if no answer and no default.
          return ask_yesno(query, default)
docs: Ask a yes/no question.