132 lines
3.6 KiB
Plaintext
132 lines
3.6 KiB
Plaintext
{
|
|
"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": 28,
|
|
"metadata": {
|
|
"id": "vpCgcTgTjL3H"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Лабораторная работа 1: Введение в Python и Git\n",
|
|
"#Автор: Плужников Артём, Егор Петухов, группа ИНБс-4301"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"def greet(name: str) -> str:\n",
|
|
" \"\"\"Возвращает приветствие для указанного имени.\"\"\"\n",
|
|
" return f\"Привет, {name}!\"\n",
|
|
"\n",
|
|
"def compute_statistics(numbers):\n",
|
|
" \"\"\"Считает базовые статистики по списку чисел.\"\"\"\n",
|
|
" if not numbers:\n",
|
|
" return None\n",
|
|
" return {\n",
|
|
" \"count\": len(numbers),\n",
|
|
" \"sum\": sum(numbers),\n",
|
|
" \"min\": min(numbers),\n",
|
|
" \"max\": max(numbers),\n",
|
|
" \"avg\": sum(numbers) / len(numbers),\n",
|
|
" }"
|
|
],
|
|
"metadata": {
|
|
"id": "8hUGAyi8jrzi"
|
|
},
|
|
"execution_count": 29,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# 1. Приветствие\n",
|
|
"print(greet(\"Студент\"))\n",
|
|
"\n",
|
|
"# 2. Работа со списком\n",
|
|
"sample = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]\n",
|
|
"stats = compute_statistics(sample)\n",
|
|
"print(f\"Список: {sample}\")\n",
|
|
"for key, value in stats.items():\n",
|
|
" print(f\" {key:>5}: {value}\")"
|
|
],
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "wUcGE8CjjzE-",
|
|
"outputId": "5ce87d69-8cbe-4eef-b5b3-758f4b49eb95"
|
|
},
|
|
"execution_count": 30,
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stdout",
|
|
"text": [
|
|
"Привет, Студент!\n",
|
|
"Список: [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]\n",
|
|
" count: 10\n",
|
|
" sum: 39\n",
|
|
" min: 1\n",
|
|
" max: 9\n",
|
|
" avg: 3.9\n"
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"def factorial(n: int) -> int:\n",
|
|
" \"\"\"Рекурсивный факториал. n >= 0.\"\"\"\n",
|
|
" if n < 0:\n",
|
|
" raise ValueError(\"factorial не определён для отрицательных чисел\")\n",
|
|
" return 1 if n <= 1 else n * factorial(n - 1)"
|
|
],
|
|
"metadata": {
|
|
"id": "ig6llIpyxFgF"
|
|
},
|
|
"execution_count": 31,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"print(f\"5! = {factorial(5)}\")\n",
|
|
"print(f\"10! = {factorial(10)}\")"
|
|
],
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "uY-uaNMdxOBF",
|
|
"outputId": "238436d9-a806-45eb-e251-360cf52a8ef5"
|
|
},
|
|
"execution_count": 32,
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stdout",
|
|
"text": [
|
|
"5! = 120\n",
|
|
"10! = 3628800\n"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
} |