From 61b4406b275830a634e02c074793a284503838e9 Mon Sep 17 00:00:00 2001 From: ArtemPlugnokov <167459091+ArtemPlugnokov@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:47:08 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD?= =?UTF-8?q?=D1=82=2004=20-=20=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=B8=D1=82=D0=B5=D1=80=D0=B0=D1=82=D0=B8=D0=B2?= =?UTF-8?q?=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab1_04_ipynb.ipynb | 122 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 lab1_04_ipynb.ipynb diff --git a/lab1_04_ipynb.ipynb b/lab1_04_ipynb.ipynb new file mode 100644 index 0000000..bb5f5e2 --- /dev/null +++ b/lab1_04_ipynb.ipynb @@ -0,0 +1,122 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "id": "vpCgcTgTjL3H" + }, + "outputs": [], + "source": [ + "# Лабораторная работа 1. Вариант 4\n", + "#*Факториал (итеративно)**\n", + "\n", + "#Авторы: *Плужников Артём, Петухов Егор*, группа *ИНБс-4301*" + ] + }, + { + "cell_type": "code", + "source": [ + "def factorial(n: int) -> int:\n", + " \"\"\"\n", + " Вычисляет факториал числа n итеративно (через цикл).\n", + "\n", + " Параметры:\n", + " n (int): целое число ≥ 0\n", + "\n", + " Возвращает:\n", + " int: значение n!\n", + " \"\"\"\n", + " # Проверка, что n — целое число\n", + " if not isinstance(n, int):\n", + " raise TypeError(\"n должно быть целым числом\")\n", + "\n", + " # Факториал определён только для неотрицательных чисел\n", + " if n < 0:\n", + " raise ValueError(\"факториал определён только для n ≥ 0\")\n", + "\n", + " # По определению 0! = 1\n", + " result = 1\n", + "\n", + " # Умножаем все числа от 1 до n\n", + " for i in range(1, n + 1):\n", + " result = result * i\n", + "\n", + " return result" + ], + "metadata": { + "id": "8hUGAyi8jrzi" + }, + "execution_count": 36, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "\n", + "print(\"factorial(5) =\", factorial(5))\n", + "print(\"factorial(0) =\", factorial(0))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "wUcGE8CjjzE-", + "outputId": "f8d11daf-f925-4aa1-dbfb-28be7a55dbc5" + }, + "execution_count": 37, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "factorial(5) = 120\n", + "factorial(0) = 1\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "\n", + "print(\"factorial(1) =\", factorial(1))\n", + "print(\"factorial(6) =\", factorial(6))\n", + "print(\"factorial(10) =\", factorial(10))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "ig6llIpyxFgF", + "outputId": "9e438396-b8bb-4d8f-beee-ce20ed73d52c" + }, + "execution_count": 38, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "factorial(1) = 1\n", + "factorial(6) = 720\n", + "factorial(10) = 3628800\n" + ] + } + ] + } + ] +} \ No newline at end of file