{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b4d01442",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Welcome to the Text Analyzer!\n",
      "Choose an option:\n",
      "1. Analyze text input\n",
      "2. Analyze text from a file\n",
      "3. Exit\n",
      "Enter your choice (1/2/3): 1\n",
      "Enter the text: Amjad\n",
      "\n",
      "Analysis:\n",
      "Number of words: 1\n",
      "Number of characters (including spaces): 5\n",
      "Number of lines: 1\n",
      "\n",
      "Welcome to the Text Analyzer!\n",
      "Choose an option:\n",
      "1. Analyze text input\n",
      "2. Analyze text from a file\n",
      "3. Exit\n",
      "Enter your choice (1/2/3): 3\n",
      "Exiting the program...\n"
     ]
    }
   ],
   "source": [
    "# Simple Word Counter (No GUI)\n",
    "\n",
    "def count_words_chars_lines(text):\n",
    "    # Count words\n",
    "    word_count = len(text.split())\n",
    "\n",
    "    # Count characters (including spaces)\n",
    "    char_count = len(text)\n",
    "\n",
    "    # Count lines\n",
    "    line_count = text.count('\\n') + 1  # Adding 1 for the last line if it's not terminated by a newline character\n",
    "\n",
    "    return word_count, char_count, line_count\n",
    "\n",
    "def main():\n",
    "    while True:\n",
    "        print(\"\\nWelcome to the Text Analyzer!\")\n",
    "        print(\"Choose an option:\")\n",
    "        print(\"1. Analyze text input\")\n",
    "        print(\"2. Analyze text from a file\")\n",
    "        print(\"3. Exit\")\n",
    "\n",
    "        choice = input(\"Enter your choice (1/2/3): \")\n",
    "\n",
    "        if choice == '1':\n",
    "            text = input(\"Enter the text: \")\n",
    "            word_count, char_count, line_count = count_words_chars_lines(text)\n",
    "            print(\"\\nAnalysis:\")\n",
    "            print(f\"Number of words: {word_count}\")\n",
    "            print(f\"Number of characters (including spaces): {char_count}\")\n",
    "            print(f\"Number of lines: {line_count}\")\n",
    "\n",
    "        elif choice == '2':\n",
    "            try:\n",
    "                file_path = input(\"Enter the file path: \")\n",
    "                with open(file_path, 'r') as file:\n",
    "                    text = file.read()\n",
    "                    word_count, char_count, line_count = count_words_chars_lines(text)\n",
    "                    print(\"\\nAnalysis:\")\n",
    "                    print(f\"Number of words: {word_count}\")\n",
    "                    print(f\"Number of characters (including spaces): {char_count}\")\n",
    "                    print(f\"Number of lines: {line_count}\")\n",
    "            except FileNotFoundError:\n",
    "                print(\"Error: File not found.\")\n",
    "            except Exception as e:\n",
    "                print(f\"Error: {e}\")\n",
    "\n",
    "        elif choice == '3':\n",
    "            print(\"Exiting the program...\")\n",
    "            break\n",
    "\n",
    "        else:\n",
    "            print(\"Invalid choice. Please enter 1, 2, or 3.\")\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    main()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84018104",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
