{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9fef6dfe",
   "metadata": {},
   "source": [
    "# 01-01 · Добро пожаловать в Python\n",
    "\n",
    "Практика к главе 1 книги «Python с нуля» (Cartesian School). Никакой установки не нужно —\n",
    "это ваш самый первый контакт с работающим кодом."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70c8f3ce",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Почувствовать, каково это — запускать код и сразу видеть результат. Никакой теории, только\n",
    "первый опыт."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "465f7165",
   "metadata": {},
   "source": [
    "## Что нужно знать\n",
    "\n",
    "Ничего. Правда. Если вы никогда раньше не запускали код — это отличное место начать."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce508429",
   "metadata": {},
   "source": [
    "## Краткое напоминание\n",
    "\n",
    "Команда `print(...)` выводит на экран то, что вы ей передали. Текст в Python всегда\n",
    "заключается в кавычки — одинарные `'...'` или двойные `\"...\"`, разницы нет."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ce28a4a",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "123af533",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.385393Z",
     "iopub.status.busy": "2026-08-15T22:28:54.385284Z",
     "iopub.status.idle": "2026-08-15T22:28:54.401603Z",
     "shell.execute_reply": "2026-08-15T22:28:54.401091Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Привет, мир!\n"
     ]
    }
   ],
   "source": [
    "print(\"Привет, мир!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28a08e34",
   "metadata": {},
   "source": [
    "## Эксперимент 1\n",
    "\n",
    "Замените текст внутри кавычек на своё собственное приветствие и запустите ячейку снова."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0e456edb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.402621Z",
     "iopub.status.busy": "2026-08-15T22:28:54.402510Z",
     "iopub.status.idle": "2026-08-15T22:28:54.404934Z",
     "shell.execute_reply": "2026-08-15T22:28:54.404487Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Привет, Cartesian School!\n"
     ]
    }
   ],
   "source": [
    "print(\"Привет, Cartesian School!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e026e2e",
   "metadata": {},
   "source": [
    "## Эксперимент 2\n",
    "\n",
    "`print()` умеет выводить не только текст. Попробуйте передать ему число или даже пример\n",
    "арифметики — Python сам всё посчитает."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "13212c5b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.405887Z",
     "iopub.status.busy": "2026-08-15T22:28:54.405774Z",
     "iopub.status.idle": "2026-08-15T22:28:54.407748Z",
     "shell.execute_reply": "2026-08-15T22:28:54.407389Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "33\n",
      "42\n"
     ]
    }
   ],
   "source": [
    "print(2024 - 1991)\n",
    "print(7 * 6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2dc453ce",
   "metadata": {},
   "source": [
    "## Типичная ошибка\n",
    "\n",
    "Если убрать кавычки, Python решит, что вы обращаетесь к чему-то по имени, а не к обычному\n",
    "тексту. **Имя** — это записанная в коде метка, по которой Python ищет ранее связанное с ней\n",
    "значение или функцию. Подробно имена и переменные рассматриваются в следующем теоретическом\n",
    "разделе. Здесь достаточно знать: имя `Привет` ещё не определено, поэтому Python сообщит об\n",
    "ошибке `NameError`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7c689dc3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.408816Z",
     "iopub.status.busy": "2026-08-15T22:28:54.408713Z",
     "iopub.status.idle": "2026-08-15T22:28:54.440485Z",
     "shell.execute_reply": "2026-08-15T22:28:54.440111Z"
    },
    "tags": [
     "raises-exception"
    ]
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'Привет' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mNameError\u001b[39m                                 Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m      1\u001b[39m \u001b[38;5;66;03m# ошибка: текст без кавычек\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m print(Привет)\n",
      "\u001b[31mNameError\u001b[39m: name 'Привет' is not defined"
     ]
    }
   ],
   "source": [
    "# ошибка: текст без кавычек\n",
    "print(Привет)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "affe41e9",
   "metadata": {},
   "source": [
    "## Исправление\n",
    "\n",
    "Достаточно вернуть кавычки — тогда Python понимает, что это обычный текст, а не имя\n",
    "переменной."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "624e386d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.441778Z",
     "iopub.status.busy": "2026-08-15T22:28:54.441657Z",
     "iopub.status.idle": "2026-08-15T22:28:54.443801Z",
     "shell.execute_reply": "2026-08-15T22:28:54.443413Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Привет\n"
     ]
    }
   ],
   "source": [
    "print(\"Привет\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f0296e6",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Выведите на экран три строки: своё имя, свой любимый цвет и число, которое вам нравится.\n",
    "Каждая строка — отдельный вызов `print()`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3ca309a1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.444818Z",
     "iopub.status.busy": "2026-08-15T22:28:54.444648Z",
     "iopub.status.idle": "2026-08-15T22:28:54.447049Z",
     "shell.execute_reply": "2026-08-15T22:28:54.446616Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cartesian School\n",
      "Электрик-синий\n",
      "14\n"
     ]
    }
   ],
   "source": [
    "print(\"Cartesian School\")\n",
    "print(\"Электрик-синий\")\n",
    "print(14)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec2841a6",
   "metadata": {},
   "source": [
    "## Самостоятельная практика\n",
    "\n",
    "`print()` можно вызывать сколько угодно раз подряд — а значит, из символов на экране можно\n",
    "собрать простую картинку. Попробуйте нарисовать текстом что-нибудь своё: домик, ёлочку,\n",
    "смайлик — что угодно из символов клавиатуры."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e1a23aa4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.447934Z",
     "iopub.status.busy": "2026-08-15T22:28:54.447833Z",
     "iopub.status.idle": "2026-08-15T22:28:54.449848Z",
     "shell.execute_reply": "2026-08-15T22:28:54.449476Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  /\\  \n",
      " /  \\ \n",
      "/____\\\n"
     ]
    }
   ],
   "source": [
    "print(\"  /\\\\  \")\n",
    "print(\" /  \\\\ \")\n",
    "print(\"/____\\\\\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34742d90",
   "metadata": {},
   "source": [
    "## Дополнительная задача ★★★\n",
    "\n",
    "`print()` может принять сразу несколько значений через запятую — тогда они выводятся в одну\n",
    "строку через пробел. Выведите одной командой `print()` три разных значения: текст, число и\n",
    "результат арифметического выражения."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ea50acd2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.450792Z",
     "iopub.status.busy": "2026-08-15T22:28:54.450681Z",
     "iopub.status.idle": "2026-08-15T22:28:54.452764Z",
     "shell.execute_reply": "2026-08-15T22:28:54.452405Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Результат: 6 42\n"
     ]
    }
   ],
   "source": [
    "print(\"Результат:\", 6, 7 * 6)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c1eb16ae",
   "metadata": {},
   "source": [
    "## Заглянем внутрь: type()\n",
    "\n",
    "У каждого значения в Python есть тип — текст, число, дробное число и так далее. Функция `type()` показывает тип прямо в интерпретаторе, без каких-либо дополнительных инструментов."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "24d279bd",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.453911Z",
     "iopub.status.busy": "2026-08-15T22:28:54.453799Z",
     "iopub.status.idle": "2026-08-15T22:28:54.456061Z",
     "shell.execute_reply": "2026-08-15T22:28:54.455676Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n",
      "<class 'int'>\n",
      "<class 'float'>\n"
     ]
    }
   ],
   "source": [
    "print(type(\"Привет\"))\n",
    "print(type(42))\n",
    "print(type(3.14))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a9ca37c",
   "metadata": {},
   "source": [
    "## Спросим сам Python: help()\n",
    "\n",
    "Python умеет объяснять сам себя. Функция `help()` показывает встроенную справку по любой функции — ту же самую, что есть в официальной документации на docs.python.org, но прямо в интерпретаторе, без браузера."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a3875f04",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.457037Z",
     "iopub.status.busy": "2026-08-15T22:28:54.456930Z",
     "iopub.status.idle": "2026-08-15T22:28:54.459383Z",
     "shell.execute_reply": "2026-08-15T22:28:54.458922Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function print in module builtins:\n",
      "\n",
      "print(*args, sep=' ', end='\\n', file=None, flush=False)\n",
      "    Prints the values to a stream, or to sys.stdout by default.\n",
      "\n",
      "    sep\n",
      "      string inserted between values, default a space.\n",
      "    end\n",
      "      string appended after the last value, default a newline.\n",
      "    file\n",
      "      a file-like object (stream); defaults to the current sys.stdout.\n",
      "    flush\n",
      "      whether to forcibly flush the stream.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(print)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87c1f48e",
   "metadata": {},
   "source": [
    "## Пасхалка: дзен Python\n",
    "\n",
    "У Python есть собственный список принципов — «дзен Python», написанный Тимом Питерсом. Открыть его можно одной строкой:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e511649a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-15T22:28:54.460385Z",
     "iopub.status.busy": "2026-08-15T22:28:54.460182Z",
     "iopub.status.idle": "2026-08-15T22:28:54.472743Z",
     "shell.execute_reply": "2026-08-15T22:28:54.472268Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Zen of Python, by Tim Peters\n",
      "\n",
      "Beautiful is better than ugly.\n",
      "Explicit is better than implicit.\n",
      "Simple is better than complex.\n",
      "Complex is better than complicated.\n",
      "Flat is better than nested.\n",
      "Sparse is better than dense.\n",
      "Readability counts.\n",
      "Special cases aren't special enough to break the rules.\n",
      "Although practicality beats purity.\n",
      "Errors should never pass silently.\n",
      "Unless explicitly silenced.\n",
      "In the face of ambiguity, refuse the temptation to guess.\n",
      "There should be one-- and preferably only one --obvious way to do it.\n",
      "Although that way may not be obvious at first unless you're Dutch.\n",
      "Now is better than never.\n",
      "Although never is often better than *right* now.\n",
      "If the implementation is hard to explain, it's a bad idea.\n",
      "If the implementation is easy to explain, it may be a good idea.\n",
      "Namespaces are one honking great idea -- let's do more of those!\n"
     ]
    }
   ],
   "source": [
    "import this"
   ]
  }
 ],
 "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
}
