def count_words_chars_lines(text):
  """
  This function counts the number of words, characters (including spaces), and lines in a given text.

  Args:
      text: The text string to be analyzed.

  Returns:
      A tuple containing three integers: number of words, characters, and lines.
  """
  words = len(text.split())
  chars = len(text)
  lines = text.count('\n') + 1  # Add 1 to account for single line

  return words, chars, lines

def main():
  """
  This function prompts the user for input, counts words, characters, and lines, and displays the results.
  It also handles errors and offers the option for multiple inputs.
  """
  while True:
    # Get user input (text or filename)
    user_input = input("Enter text or filename (or 'exit' to quit): ")

    if user_input.lower() == 'exit':
      break

    try:
      # Read from file if filename provided
      if '.' in user_input:
        with open(user_input, 'r') as file:
          text = file.read()
      else:
        text = user_input  # Use the input string directly

      # Count words, characters, and lines
      words, chars, lines = count_words_chars_lines(text)

      # Display results
      print(f"Number of words: {words}")
      print(f"Number of characters: {chars}")
      print(f"Number of lines: {lines}")

    except FileNotFoundError:
      print("Error: File not found.")
    except Exception as e:
      print(f"An error occurred: {e}")

  print("Exiting program...")

if __name__ == "__main__":
  main()
