{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1b6ad944",
   "metadata": {},
   "source": [
    "# 04-22 · Debugowanie błędów numerycznych\n",
    "\n",
    "Praktyka do sekcji [„Błędy numeryczne i debugowanie”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0880b460",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Znajdź i poprawi typowe błędy numeryczne."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6416720f",
   "metadata": {},
   "source": [
    "## Sprawa robocza\n",
    "\n",
    "Ta komórka działa poprawnie — rozgrzewka przed szukaniem błędów."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "34249b00",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:04:14.330786Z",
     "iopub.status.busy": "2026-08-16T10:04:14.330682Z",
     "iopub.status.idle": "2026-08-16T10:04:14.357648Z",
     "shell.execute_reply": "2026-08-16T10:04:14.357208Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    }
   ],
   "source": [
    "price = 100\n",
    "quantity = 2\n",
    "print(price * quantity)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa622051",
   "metadata": {},
   "source": [
    "## Laboratorium 1 · ValueError\n",
    "\n",
    "Ta komórka odpada – przeczytaj błąd, a następnie popraw go poniżej."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a4132423",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:04:14.358897Z",
     "iopub.status.busy": "2026-08-16T10:04:14.358775Z",
     "iopub.status.idle": "2026-08-16T10:04:14.383997Z",
     "shell.execute_reply": "2026-08-16T10:04:14.383471Z"
    },
    "tags": [
     "raises-exception"
    ]
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "invalid literal for int() with base 10: 'FF'",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mValueError\u001b[39m                                Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m print(int(\u001b[33m\"FF\"\u001b[39m))\n",
      "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: 'FF'"
     ]
    }
   ],
   "source": [
    "print(int(\"FF\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec8b01bd",
   "metadata": {},
   "source": [
    "## Poprawka 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2a8d1303",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:04:14.385058Z",
     "iopub.status.busy": "2026-08-16T10:04:14.384943Z",
     "iopub.status.idle": "2026-08-16T10:04:14.387099Z",
     "shell.execute_reply": "2026-08-16T10:04:14.386689Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "255\n"
     ]
    }
   ],
   "source": [
    "print(int(\"FF\", 16))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab211287",
   "metadata": {},
   "source": [
    "## Laboratorium 2 · ZeroDivisionError"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "63b85601",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:04:14.388006Z",
     "iopub.status.busy": "2026-08-16T10:04:14.387904Z",
     "iopub.status.idle": "2026-08-16T10:04:14.394820Z",
     "shell.execute_reply": "2026-08-16T10:04:14.394387Z"
    },
    "tags": [
     "raises-exception"
    ]
   },
   "outputs": [
    {
     "ename": "ZeroDivisionError",
     "evalue": "division by zero",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mZeroDivisionError\u001b[39m                         Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m      1\u001b[39m price = \u001b[32m100\u001b[39m\n\u001b[32m      2\u001b[39m quantity = \u001b[32m0\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m print(price / quantity)\n",
      "\u001b[31mZeroDivisionError\u001b[39m: division by zero"
     ]
    }
   ],
   "source": [
    "price = 100\n",
    "quantity = 0\n",
    "print(price / quantity)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16fd1667",
   "metadata": {},
   "source": [
    "## Poprawka 2\n",
    "\n",
    "Sprawdź quantity przed podziałem (użyj dowolnej wartości niezerowej)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "261296e1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:04:14.395814Z",
     "iopub.status.busy": "2026-08-16T10:04:14.395708Z",
     "iopub.status.idle": "2026-08-16T10:04:14.397989Z",
     "shell.execute_reply": "2026-08-16T10:04:14.397605Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "25.0\n"
     ]
    }
   ],
   "source": [
    "price = 100\n",
    "quantity = 4\n",
    "print(price / quantity)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "287ad5d0",
   "metadata": {},
   "source": [
    "## Podstawowa praktyka zadań ★\n",
    "\n",
    "Wybierz właściwy typ dla dokładnej kwoty czeku 19,99 + 5,50 – Decimal, nie float."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2e0c4660",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:04:14.399025Z",
     "iopub.status.busy": "2026-08-16T10:04:14.398857Z",
     "iopub.status.idle": "2026-08-16T10:04:14.401079Z",
     "shell.execute_reply": "2026-08-16T10:04:14.400660Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "25.49\n"
     ]
    }
   ],
   "source": [
    "from decimal import Decimal\n",
    "total = Decimal(\"19.99\") + Decimal(\"5.50\")\n",
    "print(total)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "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.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
