{"cells":[{"cell_type":"markdown","id":"f1501708","metadata":{"id":"f1501708"},"source":["# Python Basics — 30 практичних задач (легкий рівень)\n","**Теми:** змінні, списки, `if`, `while`, словники, функції (по 5 завдань кожна).  \n","Формат кожної задачі: коротка умова → стартовий код із `# TODO` → автотести `assert`.\n","\n","\n"]},{"cell_type":"markdown","id":"b0ef678a","metadata":{"id":"b0ef678a"},"source":["## 🛠️ Сервісні інструменти"]},{"cell_type":"code","execution_count":null,"id":"7dde5fd4","metadata":{"id":"7dde5fd4"},"outputs":[],"source":["# @title Кнопка: очистити вивід\n","from IPython.display import clear_output\n","def clear_all_output():\n","    clear_output(wait=True)\n","print(\"Готово. Викличте clear_all_output() щоб очистити вивід!\")"]},{"cell_type":"markdown","id":"8f4ba502","metadata":{"id":"8f4ba502"},"source":["## Зміст\n","1. [Змінні (5)](#vars)\n","2. [Списки (5)](#lists)\n","3. [if (5)](#if)\n","4. [while (5)](#while)\n","5. [Словники (5)](#dicts)\n","6. [Функції (5)](#funcs)"]},{"cell_type":"markdown","id":"d40ee03c","metadata":{"id":"d40ee03c"},"source":["## 1) Змінні (5) {#vars}"]},{"cell_type":"markdown","id":"765ea94a","metadata":{"id":"765ea94a"},"source":["### V1. Оголосіть змінні різних типів"]},{"cell_type":"code","execution_count":null,"id":"80769aa5","metadata":{"id":"80769aa5"},"outputs":[],"source":["# TODO: створіть змінні city (str), year (int), price (float), is_open (bool)\n","city = ...\n","year = ...\n","price = ...\n","is_open = ...\n","\n","assert isinstance(city, str) and isinstance(year, int)\n","assert isinstance(price, float) and isinstance(is_open, bool)\n","print(\"OK\")"]},{"cell_type":"markdown","id":"e0408315","metadata":{"id":"e0408315"},"source":["### V2. Конкатенація та f-string"]},{"cell_type":"code","execution_count":null,"id":"fb157793","metadata":{"id":"fb157793"},"outputs":[],"source":["name = \"Оля\"; lang = \"Python\"\n","# TODO: створіть рядок msg формату: \"Оля вивчає Python\"\n","msg = ...\n","\n","assert msg == \"Оля вивчає Python\"\n","print(\"OK\")"]},{"cell_type":"markdown","id":"91133021","metadata":{"id":"91133021"},"source":["### V3. Перетворення типів"]},{"cell_type":"code","execution_count":null,"id":"e26bb671","metadata":{"id":"e26bb671"},"outputs":[],"source":["# TODO: перетворіть рядки у числа і порахуйте total = 18.5\n","a, b, c = \"5\", \"8.5\", \"5\"\n","total = ...\n","\n","assert abs(total - 18.5) < 1e-9\n","print(\"OK\")"]},{"cell_type":"markdown","id":"5b6e5d6c","metadata":{"id":"5b6e5d6c"},"source":["### V4. Довжина рядка"]},{"cell_type":"code","execution_count":null,"id":"9bb7a90b","metadata":{"id":"9bb7a90b"},"outputs":[],"source":["text = \"communication\"\n","# TODO: length = довжина тексту\n","length = ...\n","\n","assert length == 13\n","print(\"OK\")"]},{"cell_type":"markdown","id":"d76d8b94","metadata":{"id":"d76d8b94"},"source":["### V5. Округлення float"]},{"cell_type":"code","execution_count":null,"id":"1dd13329","metadata":{"id":"1dd13329"},"outputs":[],"source":["x = 3.14159\n","# TODO: round2 = x округлений до 2 знаків після коми (використайте round)\n","round2 = ...\n","\n","assert abs(round2 - 3.14) < 1e-9\n","print(\"OK\")"]},{"cell_type":"markdown","id":"21da0f0d","metadata":{"id":"21da0f0d"},"source":["## 2) Списки (5) {#lists}"]},{"cell_type":"markdown","id":"fa479260","metadata":{"id":"fa479260"},"source":["### L1. Доступ за індексом"]},{"cell_type":"code","execution_count":null,"id":"2ed48aed","metadata":{"id":"2ed48aed"},"outputs":[],"source":["nums = [10, 20, 30, 40]\n","# TODO: first = перший елемент, last = останній елемент\n","first = ...\n","last = ...\n","\n","assert first == 10 and last == 40\n","print(\"OK\")"]},{"cell_type":"markdown","id":"d37f9cc3","metadata":{"id":"d37f9cc3"},"source":["### L2. Додавання елементів"]},{"cell_type":"code","execution_count":null,"id":"b90a3380","metadata":{"id":"b90a3380"},"outputs":[],"source":["fruits = [\"apple\", \"banana\"]\n","# TODO: додайте \"orange\" у кінець та \"kiwi\" на початок\n","...  # append\n","...  # insert\n","\n","assert fruits == [\"kiwi\", \"apple\", \"banana\", \"orange\"]\n","print(\"OK\")"]},{"cell_type":"markdown","id":"34d3f7fe","metadata":{"id":"34d3f7fe"},"source":["### L3. Зрізи (slices)"]},{"cell_type":"code","execution_count":null,"id":"295b62c2","metadata":{"id":"295b62c2"},"outputs":[],"source":["letters = ['a','b','c','d','e']\n","# TODO: mid = ['b','c','d'] (середні 3)\n","mid = ...\n","\n","assert mid == ['b','c','d']\n","print(\"OK\")"]},{"cell_type":"markdown","id":"ff2f53c6","metadata":{"id":"ff2f53c6"},"source":["### L4. List comprehension: квадрати"]},{"cell_type":"code","execution_count":null,"id":"e4e91dc6","metadata":{"id":"e4e91dc6"},"outputs":[],"source":["nums = [1,2,3,4,5]\n","# TODO: squares = [1,4,9,16,25]\n","squares = ...\n","\n","assert squares == [1,4,9,16,25]\n","print(\"OK\")"]},{"cell_type":"markdown","id":"df4262a2","metadata":{"id":"df4262a2"},"source":["### L5. Об'єднання та сортування"]},{"cell_type":"code","execution_count":null,"id":"2e5af550","metadata":{"id":"2e5af550"},"outputs":[],"source":["a = [3,1,2]\n","b = [6,4,5]\n","# TODO: merged_sorted = [1,2,3,4,5,6]\n","merged_sorted = ...\n","\n","assert merged_sorted == [1,2,3,4,5,6]\n","print(\"OK\")"]},{"cell_type":"markdown","id":"114567e3","metadata":{"id":"114567e3"},"source":["## 3) if (5) {#if}"]},{"cell_type":"markdown","id":"ea3b5fe5","metadata":{"id":"ea3b5fe5"},"source":["### IF1. Парність числа"]},{"cell_type":"code","execution_count":null,"id":"faa25813","metadata":{"id":"faa25813"},"outputs":[],"source":["n = 15\n","# TODO: is_even = True якщо n парне, інакше False\n","is_even = ...\n","\n","assert is_even is False\n","print(\"OK\")"]},{"cell_type":"markdown","id":"f72bd50a","metadata":{"id":"f72bd50a"},"source":["### IF2. Класифікація температури"]},{"cell_type":"code","execution_count":null,"id":"e8ae4753","metadata":{"id":"e8ae4753"},"outputs":[],"source":["t = 7\n","# TODO: status = \"cold\" якщо t<10, \"warm\" якщо 10<=t<25, \"hot\" якщо t>=25\n","status = ...\n","\n","assert status == \"cold\"\n","print(\"OK\")"]},{"cell_type":"markdown","id":"0727738b","metadata":{"id":"0727738b"},"source":["### IF3. Мінімум із трьох (без min())"]},{"cell_type":"code","execution_count":null,"id":"70132dcc","metadata":{"id":"70132dcc"},"outputs":[],"source":["a, b, c = 9, 2, 5\n","# TODO: min3 = мінімум з a,b,c (через if/elif/else)\n","min3 = ...\n","\n","assert min3 == 2\n","print(\"OK\")"]},{"cell_type":"markdown","id":"ce55aefb","metadata":{"id":"ce55aefb"},"source":["### IF4. Перевірка логіна"]},{"cell_type":"code","execution_count":null,"id":"4ab97aef","metadata":{"id":"4ab97aef"},"outputs":[],"source":["login = \"student\"\n","# TODO: msg = \"ok\" якщо login не пустий, інакше \"empty\"\n","msg = ...\n","\n","assert msg == \"ok\"\n","print(\"OK\")"]},{"cell_type":"markdown","id":"d4b49c5c","metadata":{"id":"d4b49c5c"},"source":["### IF5. Оцінка за балом"]},{"cell_type":"code","execution_count":null,"id":"a9abfa38","metadata":{"id":"a9abfa38"},"outputs":[],"source":["score = 73\n","# TODO: grade: A(90+), B(80-89), C(70-79), D(60-69), F(<60)\n","grade = ...\n","\n","assert grade == \"C\"\n","print(\"OK\")"]},{"cell_type":"markdown","id":"69979591","metadata":{"id":"69979591"},"source":["## 4) while (5) {#while}"]},{"cell_type":"markdown","id":"ef8f3602","metadata":{"id":"ef8f3602"},"source":["### W1. Сума 1..n за while"]},{"cell_type":"code","execution_count":null,"id":"9205749b","metadata":{"id":"9205749b"},"outputs":[],"source":["n = 5\n","# TODO: обчисліть s = 1+2+...+n через while\n","s = 0\n","i = 1\n","while ...:\n","    ...\n","assert s == 15\n","print(\"OK\")"]},{"cell_type":"markdown","id":"732032e5","metadata":{"id":"732032e5"},"source":["### W2. Піднесення 2^k > 100"]},{"cell_type":"code","execution_count":null,"id":"a69da7fd","metadata":{"id":"a69da7fd"},"outputs":[],"source":["# TODO: знайдіть мінімальний k, для якого 2^k > 100\n","k = 0\n","while ...:\n","    k += 1\n","assert 2**k > 100 and 2**(k-1) <= 100\n","print(\"OK\")"]},{"cell_type":"markdown","id":"557dc4df","metadata":{"id":"557dc4df"},"source":["### W3. Лічильник чотних до 20"]},{"cell_type":"code","execution_count":null,"id":"bbceb78e","metadata":{"id":"bbceb78e"},"outputs":[],"source":["# TODO: порахуйте, скільки парних чисел у діапазоні [1,20]\n","count = 0\n","x = 1\n","while x <= 20:\n","    ...\n","    x += 1\n","assert count == 10\n","print(\"OK\")"]},{"cell_type":"markdown","id":"f63b3e07","metadata":{"id":"f63b3e07"},"source":["### W4. Факторіал через while"]},{"cell_type":"code","execution_count":null,"id":"1b068e33","metadata":{"id":"1b068e33"},"outputs":[],"source":["n = 6\n","# TODO: fact = 720 (через while)\n","fact = 1\n","i = 2\n","while ...:\n","    ...\n","assert fact == 720\n","print(\"OK\")"]},{"cell_type":"markdown","id":"90dda9ad","metadata":{"id":"90dda9ad"},"source":["### W5. Сума цифр числа"]},{"cell_type":"code","execution_count":null,"id":"4794263f","metadata":{"id":"4794263f"},"outputs":[],"source":["num = 12345\n","# TODO: знайдіть суму цифр num через while\n","s = 0\n","x = num\n","while x > 0:\n","    ...\n","assert s == 15\n","print(\"OK\")"]},{"cell_type":"markdown","id":"ce9d3da8","metadata":{"id":"ce9d3da8"},"source":["## 5) Словники (5) {#dicts}"]},{"cell_type":"markdown","id":"2f275422","metadata":{"id":"2f275422"},"source":["### D1. Створення словника"]},{"cell_type":"code","execution_count":null,"id":"da949787","metadata":{"id":"da949787"},"outputs":[],"source":["# TODO: створіть словник person з ключами name, age, city\n","person = ...\n","\n","assert isinstance(person, dict)\n","assert set(person.keys()) == {\"name\",\"age\",\"city\"}\n","print(\"OK\")"]},{"cell_type":"markdown","id":"3b932458","metadata":{"id":"3b932458"},"source":["### D2. Доступ і зміна значення"]},{"cell_type":"code","execution_count":null,"id":"ff704a14","metadata":{"id":"ff704a14"},"outputs":[],"source":["user = {\"name\":\"Ira\",\"role\":\"student\"}\n","# TODO: змініть роль на \"admin\"\n","...\n","\n","assert user[\"role\"] == \"admin\"\n","print(\"OK\")"]},{"cell_type":"markdown","id":"25e2153c","metadata":{"id":"25e2153c"},"source":["### D3. Підрахунок частоти слів"]},{"cell_type":"code","execution_count":null,"id":"6e0ebf5c","metadata":{"id":"6e0ebf5c"},"outputs":[],"source":["text = \"a a b b b c\"\n","# TODO: побудуйте словник частот: {'a':2,'b':3,'c':1}\n","freq = {}\n","for w in text.split():\n","    ...\n","assert freq == {'a':2,'b':3,'c':1}\n","print(\"OK\")"]},{"cell_type":"markdown","id":"1c5ee538","metadata":{"id":"1c5ee538"},"source":["### D4. Об'єднання словників"]},{"cell_type":"code","execution_count":null,"id":"e7494f79","metadata":{"id":"e7494f79"},"outputs":[],"source":["a = {\"x\":1,\"y\":2}\n","b = {\"y\":3,\"z\":4}\n","# TODO: merged = {'x':1,'y':3,'z':4} (значення з b мають пріоритет)\n","merged = ...\n","\n","assert merged == {'x':1,'y':3,'z':4}\n","print(\"OK\")"]},{"cell_type":"markdown","id":"1c2a7abf","metadata":{"id":"1c2a7abf"},"source":["### D5. Інверсія словника (ключі↔значення)"]},{"cell_type":"code","execution_count":null,"id":"f18c74ce","metadata":{"id":"f18c74ce"},"outputs":[],"source":["pairs = {\"a\":1,\"b\":2,\"c\":3}\n","# TODO: inv = {1:\"a\",2:\"b\",3:\"c\"}\n","inv = ...\n","\n","assert inv == {1:\"a\",2:\"b\",3:\"c\"}\n","print(\"OK\")"]},{"cell_type":"markdown","id":"1639024f","metadata":{"id":"1639024f"},"source":["## 6) Функції (5) {#funcs}"]},{"cell_type":"markdown","id":"a84389c5","metadata":{"id":"a84389c5"},"source":["### F1. Функція привітання"]},{"cell_type":"code","execution_count":null,"id":"b3cb6040","metadata":{"id":"b3cb6040"},"outputs":[],"source":["# TODO: напишіть greet(name) -> \"Привіт, {name}!\"\n","def greet(name):\n","    ...\n","\n","assert greet(\"Іван\") == \"Привіт, Іван!\"\n","print(\"OK\")"]},{"cell_type":"markdown","id":"0291ab91","metadata":{"id":"0291ab91"},"source":["### F2. Добуток двох чисел"]},{"cell_type":"code","execution_count":null,"id":"d9c054cc","metadata":{"id":"d9c054cc"},"outputs":[],"source":["# TODO: mul(a,b) -> a*b\n","def mul(a,b):\n","    ...\n","assert mul(3,4) == 12\n","print(\"OK\")"]},{"cell_type":"markdown","id":"aa676e06","metadata":{"id":"aa676e06"},"source":["### F3. Максимум у списку (без max())"]},{"cell_type":"code","execution_count":null,"id":"427866ba","metadata":{"id":"427866ba"},"outputs":[],"source":["# TODO: my_max(lst) -> найбільший елемент\n","def my_max(lst):\n","    ...\n","\n","assert my_max([1,5,2,4]) == 5\n","print(\"OK\")"]},{"cell_type":"markdown","id":"b29df82e","metadata":{"id":"b29df82e"},"source":["### F4. Фільтр парних (через функцію)"]},{"cell_type":"code","execution_count":null,"id":"7bcf93e8","metadata":{"id":"7bcf93e8"},"outputs":[],"source":["# TODO: only_even(lst) -> список лише парних\n","def only_even(lst):\n","    ...\n","\n","assert only_even([1,2,3,4,5,6]) == [2,4,6]\n","print(\"OK\")"]},{"cell_type":"markdown","id":"c4566bd6","metadata":{"id":"c4566bd6"},"source":["### F5. Підрахунок голосних у рядку"]},{"cell_type":"code","execution_count":null,"id":"7d7ab333","metadata":{"id":"7d7ab333"},"outputs":[],"source":["# TODO: vowels_count(s) -> кількість голосних (aeiouy) незалежно від регістру\n","def vowels_count(s):\n","    ...\n","\n","assert vowels_count(\"Hello\") == 2\n","assert vowels_count(\"PYTHON\") == 1\n","print(\"OK\")"]}],"metadata":{"colab":{"provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"}},"nbformat":4,"nbformat_minor":5}