{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "beNZbR7NRuYI",
        "outputId": "85841bad-cc0e-4d68-d7da-005a94c481e0"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Welcome to the Number Guessing Game!\n",
            "I have chosen a number between 1 and 100. Try to guess it.\n",
            "Enter your guess: 5\n",
            "Too low. Try again.\n",
            "Remaining attempts: 9\n",
            "Enter your guess: 55\n",
            "Too low. Try again.\n",
            "Remaining attempts: 8\n",
            "Enter your guess: 88\n",
            "Too low. Try again.\n",
            "Remaining attempts: 7\n",
            "Enter your guess: 100\n",
            "Too high. Try again.\n",
            "Remaining attempts: 6\n",
            "Enter your guess: 90\n",
            "Too low. Try again.\n",
            "Remaining attempts: 5\n",
            "Enter your guess: 95\n",
            "Too low. Try again.\n",
            "Remaining attempts: 4\n",
            "Enter your guess: 99\n",
            "Congratulations! You guessed the correct number: 99\n"
          ]
        }
      ],
      "source": [
        "# 2nd Miduim Assigment\n",
        "import random\n",
        "\n",
        "def guess_the_number():\n",
        "    print(\"Welcome to the Number Guessing Game!\")\n",
        "    print(\"I have chosen a number between 1 and 100. Try to guess it.\")\n",
        "\n",
        "    # Set the range and the number of attempts\n",
        "    secret_number = random.randint(1, 100)\n",
        "    max_attempts = 10\n",
        "    attempts = 0\n",
        "\n",
        "    while attempts < max_attempts:\n",
        "        guess = int(input(\"Enter your guess: \"))\n",
        "\n",
        "        if guess == secret_number:\n",
        "            print(\"Congratulations! You guessed the correct number:\", secret_number)\n",
        "            break\n",
        "        elif guess < secret_number:\n",
        "            print(\"Too low. Try again.\")\n",
        "        else:\n",
        "            print(\"Too high. Try again.\")\n",
        "\n",
        "        attempts += 1\n",
        "        remaining_attempts = max_attempts - attempts\n",
        "        print(\"Remaining attempts:\", remaining_attempts)\n",
        "\n",
        "    if attempts == max_attempts:\n",
        "        print(\"Sorry, you've run out of attempts. The correct number was:\", secret_number)\n",
        "\n",
        "if __name__ == \"__main__\":\n",
        "    guess_the_number()\n"
      ]
    }
  ]
}