{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Python for Beginners: Variables, Data Types, and Operators\n",
        "\n",
        "This is part 1 of the Python Fundamentals series. No programming experience is required.\n",
        "\n",
        "Run each cell in order."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Your first Python program\n",
        "\n",
        "Python executes instructions in order. The print function displays a value in the notebook output. Text must be enclosed in quotes."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "print(\"Hello, Python!\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Variables and assignment\n",
        "\n",
        "A variable is a name associated with a value. Assignment uses a single equals sign. Python names are case-sensitive and cannot begin with a digit. Use descriptive names."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "sample_count = 100\n",
        "learning_rate = 0.01\n",
        "print(sample_count, learning_rate)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Basic data types\n",
        "\n",
        "Integers represent whole numbers, floats represent floating-point numbers, strings represent text, and Booleans represent True or False. None represents the absence of a value. Python determines types at runtime."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "values = [42, 3.14, \"Python\", True, None]\n",
        "for value in values:\n",
        "    print(value, type(value).__name__)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Arithmetic operators\n",
        "\n",
        "Addition, subtraction, multiplication and division use +, -, * and /. Floor division uses //, remainder uses %, and exponentiation uses **. Parentheses control evaluation order."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "print(7 + 3, 7 - 3, 7 * 3, 7 / 3)\n",
        "print(7 // 3, 7 % 3, 7 ** 2)\n",
        "print((2 + 3) * 4)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Strings and formatting\n",
        "\n",
        "Strings can be combined with +. Indexing starts at zero. An f-string inserts values into text using braces. Strings are immutable."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "name = \"Python\"\n",
        "score = 0.875\n",
        "print(name[0], name.lower(), len(name))\n",
        "print(f\"Accuracy: {score:.1%}\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Comparisons and Boolean logic\n",
        "\n",
        "Comparisons return Boolean values. Equality uses ==, inequality uses !=, and ordering uses <, >, <= and >=. The operators and, or and not combine conditions."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "accuracy = 0.92\n",
        "minimum = 0.90\n",
        "print(accuracy >= minimum)\n",
        "print(accuracy >= minimum and accuracy <= 1.0)\n",
        "print(not (accuracy == minimum))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Type conversion\n",
        "\n",
        "Use int, float and str to convert compatible values. Converting a decimal float to an integer truncates toward zero. Invalid numeric strings raise ValueError."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "text = \"42\"\n",
        "count = int(text)\n",
        "print(count + 8)\n",
        "print(float(\"3.5\"), str(count), int(3.9))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Practical example: dataset statistics\n",
        "\n",
        "Suppose 180 of 200 predictions are correct. Divide the number correct by the total to calculate accuracy. This is arithmetic, not model training."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "correct = 180\n",
        "total = 200\n",
        "accuracy = correct / total\n",
        "print(f\"Accuracy: {accuracy:.2%}\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Practice exercises\n",
        "\n",
        "Try these before viewing the solutions."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Calculate the mean of 12, 18 and 24."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Convert the string \"0.85\" to a number and test whether it exceeds 0.8."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Exercise solutions"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "print((12 + 18 + 24) / 3)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "print(float(\"0.85\") > 0.8)"
      ],
      "execution_count": null,
      "outputs": []
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}