{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d07466d2",
   "metadata": {},
   "source": [
    "# 10-15 · Walidacja wejść w pętli\n",
    "\n",
    "Praktyka do sekcji [„Checking input in a loop”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d407b49b",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Pytaj użytkownika w pętli, aż dane będą poprawne."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b2e8660",
   "metadata": {},
   "source": [
    "## Pro input() w tym laptopie\n",
    "\n",
    "Ten laptop jest automatyczny, bez żywej osoby przy klawiaturze – dlatego tu jest `input()` tymczasowo zastąpione wcześniej przygotowanymi odpowiedziami."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2905d31b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:12:52.459442Z",
     "iopub.status.busy": "2026-08-16T20:12:52.459244Z",
     "iopub.status.idle": "2026-08-16T20:12:52.477375Z",
     "shell.execute_reply": "2026-08-16T20:12:52.476878Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['abc', '', '15'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75a5eadc",
   "metadata": {},
   "source": [
    "## Podstawowa praktyka zadań ★"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dbcd3540",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:12:52.478556Z",
     "iopub.status.busy": "2026-08-16T20:12:52.478440Z",
     "iopub.status.idle": "2026-08-16T20:12:52.481082Z",
     "shell.execute_reply": "2026-08-16T20:12:52.480649Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Введите возраст: abc\n",
      "Нужно ввести число!\n",
      "Введите возраст: \n",
      "Нужно ввести число!\n",
      "Введите возраст: 15\n",
      "Спасибо! Вам 15 лет\n"
     ]
    }
   ],
   "source": [
    "vozrast = input(\"Введите возраст: \")\n",
    "while not vozrast.isdigit():\n",
    "    print(\"Нужно ввести число!\")\n",
    "    vozrast = input(\"Введите возраст: \")\n",
    "\n",
    "vozrast = int(vozrast)\n",
    "print(\"Спасибо! Вам\", vozrast, \"лет\")"
   ]
  }
 ],
 "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
}
