def count_words_chars_lines(text):
  """
  This function takes a text string as input and returns a dictionary containing the word count, character count, and line count.
  """
  # Split the text into words
  words = text.split()

  # Count the number of words
  word_count = len(words)

  # Count the number of characters (including spaces)
  char_count = len(text)

  # Count the number of lines
  line_count = text.count("\n") + 1  # Add 1 to account for single line

  return {"words": word_count, "characters": char_count, "lines": line_count}

def main():
  while True:
    # Get user input choice
    choice = input("Enter 1 to input text, 2 to read from a file, or 0 to exit: ")

    if choice == '0':
      break
    elif choice == '1':
      # Get text input from user
      text = input("Enter your text: ")
    elif choice == '2':
      # Read text from a file
      try:
        filename = input("Enter the file name: ")
        with open(filename, 'r') as f:
          text = f.read()
      except FileNotFoundError:
        print("Error: File not found!")
        continue
    else:
      print("Invalid choice. Please enter 0, 1, or 2.")
      continue

    # Count words, characters, and lines
    results = count_words_chars_lines(text)

    # Print the results
    print("Number of words:", results["words"])
    print("Number of characters:", results["characters"])
    print("Number of lines:", results["lines"])

    print("\n")

if __name__ == "__main__":
  main()