{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Python Application\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. Even Odd Number Sorter App\n",
    "\n",
    "<b>Description:</b>\n",
    "A program that sorts a list of comma separated numbers as either even or odd. Upon sorting the numbers into two groups, this program will then sort each group numerically and display the results.\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter your name: sige\n",
      "Hello sige Welcome to the Even Odd Number Sorter App\n",
      "\n",
      "Enter in a string of numbers separated by a comma (,) : 2,2,2,2,2\n",
      "\n",
      "- Result Summary ----\n",
      "\n",
      "2 is even\n",
      "2 is even\n",
      "2 is even\n",
      "2 is even\n",
      "2 is even\n",
      "2.0\n",
      "\n",
      "The following 5 numbers are even:\n",
      "2\n",
      "2\n",
      "2\n",
      "2\n",
      "2\n",
      "There are 0 odd numbers.\n"
     ]
    }
   ],
   "source": [
    "\n",
    "name = input(\"Enter your name: \")\n",
    "print(f\"Hello {name} Welcome to the Even Odd Number Sorter App\\n\")\n",
    "while True:\n",
    "    \n",
    "\n",
    "    numbers = input(\"Enter in a string of numbers separated by a comma (,) : \")\n",
    "    number_split = numbers.split(\",\")\n",
    "\n",
    "\n",
    "    print(\"\\n---- Result Summary ----\\n\")\n",
    "    for number in number_split:\n",
    "        numberr = int(number)\n",
    "        if (numberr % 2) == 0:\n",
    "            print(f\"{number} is even\")\n",
    "        else:\n",
    "            print(f\"{number} is odd\")\n",
    "    \n",
    "\n",
    "    listonly = []        \n",
    "    for item in number_split:    \n",
    "        listonly.append(int(item))\n",
    "    listonly.sort()\n",
    "    sumof = sum(listonly)\n",
    "    \n",
    "    even_count = 0\n",
    "    odd_count = 0\n",
    "    \n",
    "    for sorts in listonly:\n",
    "        if (sorts % 2) == 0:\n",
    "            even_count += 1\n",
    "        else:\n",
    "            odd_count += 1\n",
    "    \n",
    "  \n",
    "    if even_count != 0:\n",
    "        print(f\"\\nThe following {even_count} numbers are even:\")\n",
    "        for sorts in listonly:\n",
    "            if (sorts % 2) == 0:\n",
    "                print(sorts)\n",
    "                \n",
    "    else:\n",
    "        print(f\"There are {even_count} even numbers.\") \n",
    "        \n",
    "    if odd_count != 0:\n",
    "        print(f\"\\nThe following {odd_count} numbers are even:\")\n",
    "        for sorts in listonly:\n",
    "            if (sorts % 2) != 0:\n",
    "                print(sorts)\n",
    "\n",
    "    else:\n",
    "        print(f\"There are {odd_count} odd numbers.\")\n",
    "        \n",
    "    ans=input(\"Would you like to run the program again (y/n): \")\n",
    "    if ans=='n':\n",
    "        print(\"Thank you for using the program. Goodbye.\")\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. Prime Number App\n",
    "\n",
    "<b>Description:</b>\n",
    "\n",
    "A program that will either determine if a given number is prime or display all prime numbers within a given range of values. When determining all prime numbers within a given range. \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome to the Prime Number App\n",
      "Tell us your name: Mica Glaze Drio\n",
      "Hello Mica Glaze Drio Welcome to the Prime Number App\n",
      "\n",
      "Enter 1 to determine if a specific number is prime\n",
      "Enter 2 to determine all prime numbers within a set range.\n",
      "Enter your choice 1 or 2: \n",
      "2\n",
      "Enter the lower bound of your range: 4\n",
      "Enter the upper bound of your range: \n",
      "31\n",
      "Calculations took a total of seconds to calculate\n",
      "The following numbers between 4 and 31 are prime:\n",
      "Press Enter to continue.\n",
      "5\n",
      "7\n",
      "11\n",
      "13\n",
      "17\n",
      "19\n",
      "23\n",
      "29\n",
      "31\n",
      "Would you like to run the program again (y/n): n\n",
      "\n",
      "Thank you for using the program. Goodbye.\n"
     ]
    }
   ],
   "source": [
    "print(\"Welcome to the Prime Number App\")\n",
    "name = input(\"Tell us your name: \")\n",
    "print(f\"Hello {name} Welcome to the Prime Number App\")\n",
    "\n",
    "while True:\n",
    "    #asking the user what he wants to do\n",
    "    print(\"\\nEnter 1 to determine if a specific number is prime\")\n",
    "    print(\"Enter 2 to determine all prime numbers within a set range.\")\n",
    "    choice = input(\"Enter your choice 1 or 2: \\n\")\n",
    "    \n",
    "    #starting to run the user choice\n",
    "    if choice == \"1\":\n",
    "        question1 = int(input(\"Enter a number to determine if it is prime or not: \"))\n",
    "        def CheckPrime(question1):\n",
    "           if (question1 <= 1):\n",
    "              return False\n",
    "           if (question1 <= 3):\n",
    "              return True\n",
    "           if (question1 % 2 == 0 or question1 % 3 == 0):\n",
    "              return False\n",
    "           i = 5\n",
    "           while (i * i <= question1):\n",
    "              if (question1 % i == 0 or question1 % (i + 2) == 0):\n",
    "                 return False\n",
    "              i = i + 6\n",
    "           return True\n",
    "        if (CheckPrime(question1)):\n",
    "           print(f\"{question1} is prime!\")\n",
    "        else:\n",
    "           print(f\"{question1} is not prime!\")\n",
    "    elif choice == \"2\":\n",
    "        minnum = int(input(\"\\nEnter the lower bound of your range: \"))\n",
    "        maxnum = int(input(\"Enter the upper bound of your range: \\n\"))\n",
    "        print(f\"\\nCalculations took a total of seconds to calculate\")\n",
    "        print(f\"The following numbers between {minnum} and {maxnum} are prime:\")\n",
    "        input(\"Press Enter to continue.\")\n",
    "        for num in range(minnum,maxnum + 1):  \n",
    "           if num  > 1:  \n",
    "               for i in range(2, num):  \n",
    "                   if (num % i) == 0:  \n",
    "                       break  \n",
    "               else:  \n",
    "                   print(num)  \n",
    "                    \n",
    "    #asking the user if want to run the program again\n",
    "    restart = input(\"Would you like to run the program again (y/n): \")\n",
    "    if restart=='n':\n",
    "        print(\"\\nThank you for using the program. Goodbye.\")\n",
    "        break\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3. Guess My Word App\n",
    "\n",
    "<b>Description:</b>\n",
    "\n",
    "A program that plays a word guessing game with a user. Your program will provide a category of words to the user and a string of dashes “-----” that represent the length of the word. The user will guess the word and with each incorrect guess, your program will reveal a letter at random, “-a---”. Upon guessing the word correctly, your program will then inform the user how many guesses they took.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter your name: Mica Glaze Drio\n",
      "Hello Mica glaze drio Welcome to the Guess My Word App\n",
      "\n",
      "Guess a 5 letter word from the following category: fruits\n",
      "-----\n",
      "The number of allowed guesses for this word is: 4\n",
      "\n",
      "Enter your guess: banana\n",
      "That is not correct. let us reveal a letter to help you!\n",
      "MA---\n",
      "\n",
      "Enter your guess: apple\n",
      "That is not correct. let us reveal a letter to help you!\n",
      "MA---\n",
      "\n",
      "Enter your guess: mango\n",
      "\n",
      "Correct! You guessed the word in 3 guesses.\n",
      "\n",
      "Would you like to play again (y/n): n\n",
      "\n",
      "Thank you for using the program. Goodbye.\n"
     ]
    }
   ],
   "source": [
    "import random, time\n",
    "\n",
    "sports = ['basketball', 'baseball', 'soccer', 'football', 'tennis', 'curling']\n",
    "colors = ['orange', 'yellow', 'purple', 'aquamarine', 'violet', 'gold']\n",
    "fruits = ['apple', 'banana', 'watermelon', 'peach', 'mango', 'strawberry']\n",
    "classes = ['english', 'history', 'science', 'mathematics', 'art', 'health']\n",
    "\n",
    "category = ['SP', 'CO', 'FR', 'CL']\n",
    "playGame = True\n",
    "userGuesslist = []\n",
    "userGuesses = []\n",
    "\n",
    "name = input(\"Enter your name: \")\n",
    "print(\"Hello\", name.capitalize(), \"Welcome to the Guess My Word App\")\n",
    "time.sleep(1)\n",
    "\n",
    "#Choosing randomly in the category\n",
    "while True:\n",
    "    chosencat = random.choice(category)\n",
    "    secretWordList = list(chosencat)\n",
    "    if chosencat == 'CL':\n",
    "        guessword = random.choice(classes)\n",
    "        chosengroup = classes\n",
    "        groupname = \"classes\"\n",
    "    elif chosencat == 'FR':\n",
    "        guessword = random.choice(fruits)\n",
    "        chosengroup = fruits\n",
    "        groupname = \"fruits\"\n",
    "    elif chosencat == 'CO':\n",
    "        guessword = random.choice(colors)\n",
    "        chosengroup = colors\n",
    "        groupname = \"colors\"\n",
    "    elif chosencat == 'SP':\n",
    "        guessword = random.choice(sports)\n",
    "        chosengroup = sports\n",
    "        groupname = \"sports\"\n",
    "    letter = list(guessword)\n",
    "    nom = len(letter)\n",
    "    attempts = (nom - 1)\n",
    "    \n",
    "    #Giving category and revealing the number of letters\n",
    "    print(f\"\\nGuess a {nom} letter word from the following category: {groupname}\")\n",
    "    def printGuessedLetter():\n",
    "        print(''.join(userGuesslist))\n",
    "    for n in letter:\n",
    "        userGuesslist.append('-')\n",
    "    printGuessedLetter()\n",
    "    \n",
    "    #The attemps for this game is 1 lower than the guess word length\n",
    "    print(\"The number of allowed guesses for this word is:\", attempts)\n",
    "    \n",
    "    #Starting guessing the word\n",
    "    for attempt in range(attempts):\n",
    "        word = input(\"\\nEnter your guess: \")\n",
    "        if attempt == attempts:\n",
    "            print(\"You have no guess left, Let me reveal the word\")\n",
    "            printGuessedLetter()\n",
    "            break\n",
    "        elif word in userGuesses:\n",
    "            print(\"You already guessed this word, try something else.\")\n",
    "        elif word not in chosengroup:\n",
    "            print(f\"That is not even in the {groupname} category\")\n",
    "\n",
    "        else:\n",
    "            if word != guessword:\n",
    "                print(\"That is not correct. let us reveal a letter to help you!\")\n",
    "                for i in range(len(letter)):\n",
    "                    giveletter = random.choice(letter)\n",
    "                    if giveletter in letter[i]:\n",
    "                        giveletterIndex = i\n",
    "                        userGuesslist[giveletterIndex] = giveletter.upper()\n",
    "                printGuessedLetter()\n",
    "            elif word == guessword:\n",
    "                print(f\"\\nCorrect! You guessed the word in {attempt + 1} guesses.\")\n",
    "                break\n",
    "    #Asking if the user wants to play another round\n",
    "    restart = input(\"\\nWould you like to play again (y/n): \")\n",
    "    if restart.upper() =='Y':\n",
    "        userGuesslist = []\n",
    "        userGuesses = []\n",
    "    elif restart.upper() =='N':\n",
    "        print(\"\\nThank you for using the program. Goodbye.\")\n",
    "        break\n",
    "        \n",
    "        \n",
    "       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "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.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}