code: def readc(prompt, default=None, valid=None, question_mark=True):
      
  
      cresult = None  # Avoid PyCharm warning
  
      # question mark
      if question_mark:
          cquestion_mark = ' ? '
      else:
          cquestion_mark = ''
  
      # main loop
      loop = True
      while loop:
  
          # display prompt
          if default is None:
              print(prompt + cquestion_mark, end='')
              sys.stdout.flush()
          else:
              print(prompt + ' [' + str(default) + ']' + cquestion_mark, end='')
              sys.stdout.flush()
  
          # read user's input
          cresult = sys.stdin.readline().strip()
          if cresult == '' and default is not None:
              cresult = str(default)
  
          if len(cresult) == 1:
              # check that all the characters are valid
              loop = False
              if valid is not None:
                  for c in cresult:
                      if c not in str(valid):
                          print('*** Error: invalid characters found.')
                          print('*** Valid characters are:', valid)
                          print('*** Try again!')
                          loop = True
          else:
              print('*** Error: invalid string length. Try again!')
  
      return cresult
docs: Return a single character read from keyboard
  
      Parameters
      ----------
      prompt : str
          Prompt string.
      default : str
          Default value.
      valid : str
          String providing valid characters. If None, all characters are
          valid (default).
      question_mark : bool
          If True, display question mark after prompt.
  
      Returns
      -------
      cresult : str
          Read value.