From d78581c98eeb2efdfbba92da644af4304333f5a7 Mon Sep 17 00:00:00 2001 From: tomike26 Date: Mon, 7 Jul 2025 04:00:56 +0100 Subject: [PATCH 1/7] learnt numbers,and texts --- docs/lists.ipynb | 479 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 479 insertions(+) create mode 100644 docs/lists.ipynb diff --git a/docs/lists.ipynb b/docs/lists.ipynb new file mode 100644 index 0000000..c9f9046 --- /dev/null +++ b/docs/lists.ipynb @@ -0,0 +1,479 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "e5d5db00", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1+1" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "567c6e5c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['H', 'E', 'L', 'L', 'O', ' ', 'W', 'O', 'R', 'L', 'D']" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "name = []\n", + "for all in 'hello world':\n", + " name.append(all.upper())\n", + "name " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "f3be67e4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2+2" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "4bea9d66", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "20" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "50 - 5*6" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "391bc7ba", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "18 // 3" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "eb7aabd6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "19 // 3" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "0066505a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "900" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "width = 20\n", + "height = 5* 9\n", + "width * height" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "4b8074a7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14.0" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4 * 3.75 - 1" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "e8ce7e21", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14.0" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tax = 12.5 / 100\n", + "price = 100.50\n", + "price * tax \n", + "price + _\n", + "round(_,2)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "5aac856d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First name. \n", + "Second line.\n" + ] + } + ], + "source": [ + "s = \"First name. \\nSecond line.\" \n", + "print(s)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "4da91d31", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'unununium'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3 * 'un' + 'ium'" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "37d0d377", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "squares = [1, 4, 9, 16, 25]\n", + "squares[-3:]\n", + "squares + [36, 49, 64, 81, 100]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "644e351e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 8, 27, 64, 125, 64]" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cubes = [1, 8, 27, 65, 125] \n", + "4 ** 3\n", + "cubes[3] = 64\n", + "cubes.append(64)\n", + "cubes" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "38c63413", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Red', 'Green', 'Blue', 'Alph']" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rgb = [\"Red\", \"Green\", \"Blue\"]\n", + "rgba = rgb\n", + "id(rgb) == id(rgba) \n", + "rgba.append(\"Alph\")\n", + "rgb" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "c44632c4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Red', 'Green', 'Blue', 'Alpha']" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "correct_rgba = rgba[:]\n", + "correct_rgba[-1] = \"Alpha\"\n", + "correct_rgba\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b52b04fb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'b', 'f', 'g']" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']\n", + "letters[2:5] = []\n", + "letters" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec82a853", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "54028644", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "1\n", + "2\n", + "3\n", + "5\n", + "8\n" + ] + } + ], + "source": [ + "a, b = 0, 1\n", + "while a < 10: #true\n", + " print(a) #1\n", + " a, b = b, a+b # 2, 3\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "6b14b040", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Negative changed to zero\n" + ] + } + ], + "source": [ + "x = int(input(\"Please enter an integer: \"))\n", + "\n", + "if x < 0:\n", + " x = 0\n", + " print('Negative changed to zero')\n", + "elif x == 0:\n", + " print('Zero')\n", + "elif x == 1:\n", + " print('Single')\n", + "else:\n", + " print('More')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47b05c09", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "More\n" + ] + } + ], + "source": [ + "x = int(input(\"Please enter an integer:\"))\n", + "if x < 0:\n", + " x = 0\n", + " print('Negative changed to zero')\n", + "elif x == 0:\n", + " print('Zero')\n", + "else:\n", + " print('More')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cb1e5983", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pythonclass", + "language": "python", + "name": "python3" + }, + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From ef0d58cffaf6db86e8cb5a08aa79ed0f7f2f6224 Mon Sep 17 00:00:00 2001 From: tomike26 Date: Mon, 7 Jul 2025 05:38:07 +0100 Subject: [PATCH 2/7] conditional statement learning --- docs/conditional_statement.ipynb | 247 +++++++++++++++++++++++++++++++ docs/lists.ipynb | 53 ------- 2 files changed, 247 insertions(+), 53 deletions(-) create mode 100644 docs/conditional_statement.ipynb diff --git a/docs/conditional_statement.ipynb b/docs/conditional_statement.ipynb new file mode 100644 index 0000000..91b1fdd --- /dev/null +++ b/docs/conditional_statement.ipynb @@ -0,0 +1,247 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "55bb0dbd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "More\n" + ] + } + ], + "source": [ + "x = int(input(\"Please enter an integer: \"))\n", + "\n", + "if x < 0:\n", + " x = 0\n", + " print('Negative changed to zero')\n", + "elif x == 0:\n", + " print('Zero')\n", + "elif x == 1:\n", + " print('Single')\n", + "else:\n", + " print('More')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "4930aaf1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "cat 3\n", + "house 5\n", + "shoes 5\n", + "home 4\n" + ] + } + ], + "source": [ + "words= ['cat', 'house', 'shoes','home']\n", + "for w in words:\n", + " print(w,len(w))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "e88fa771", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Hans'}\n", + "{'景太郎'}\n" + ] + } + ], + "source": [ + "users = {'Hans': 'active', 'Éléonore': 'inactive', '景太郎': 'active'}\n", + "\n", + "for user, status in users.copy().items():\n", + " if status == 'inactive':\n", + " del users[user]\n", + " \n", + "\n", + "active_users = {}\n", + "for user, status in users.items():\n", + " if status == 'active':\n", + " active_users[user] = status\n", + " print({user})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f83d7439", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n" + ] + } + ], + "source": [ + "for i in range(5):\n", + " print(i)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "15435bed", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[5, 6, 7, 8, 9]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(range(5, 10))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "50e1c87a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 3, 6, 9]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(range(0, 10, 3))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "b1fda00c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[-10, -40, -70]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(range(-10, -100, -30))" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "7764cca5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4 equals 2 * 2\n", + "6 equals 2 * 3\n", + "8 equals 2 * 4\n", + "9 equals 3 * 3\n" + ] + } + ], + "source": [ + "for n in range(2, 10):\n", + " for x in range(2, n):\n", + " if n % x == 0:\n", + " print(f\"{n} equals {x} * {n//x}\")\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "c80a3f23", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found an even number 2\n", + "Found an odd number 3\n", + "Found an even number 4\n", + "Found an odd number 5\n", + "Found an even number 6\n", + "Found an odd number 7\n", + "Found an even number 8\n", + "Found an odd number 9\n" + ] + } + ], + "source": [ + "for num in range(2, 10):\n", + " if num % 2 == 0:\n", + " print(f\"Found an even number {num}\")\n", + " continue\n", + " print(f\"Found an odd number {num}\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pythonclass", + "language": "python", + "name": "python3" + }, + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/lists.ipynb b/docs/lists.ipynb index c9f9046..7483444 100644 --- a/docs/lists.ipynb +++ b/docs/lists.ipynb @@ -393,59 +393,6 @@ " a, b = b, a+b # 2, 3\n" ] }, - { - "cell_type": "code", - "execution_count": 6, - "id": "6b14b040", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Negative changed to zero\n" - ] - } - ], - "source": [ - "x = int(input(\"Please enter an integer: \"))\n", - "\n", - "if x < 0:\n", - " x = 0\n", - " print('Negative changed to zero')\n", - "elif x == 0:\n", - " print('Zero')\n", - "elif x == 1:\n", - " print('Single')\n", - "else:\n", - " print('More')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "47b05c09", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "More\n" - ] - } - ], - "source": [ - "x = int(input(\"Please enter an integer:\"))\n", - "if x < 0:\n", - " x = 0\n", - " print('Negative changed to zero')\n", - "elif x == 0:\n", - " print('Zero')\n", - "else:\n", - " print('More')" - ] - }, { "cell_type": "code", "execution_count": null, From 9c00ef74236b7096cff8df727e3f37c18a9199c9 Mon Sep 17 00:00:00 2001 From: tomike26 Date: Mon, 7 Jul 2025 13:38:59 +0100 Subject: [PATCH 3/7] object_classes --- docs/conditional_statement.ipynb | 144 ++++++++++++++++++++++------ docs/object_classes.statement.ipynb | 69 +++++++++++++ 2 files changed, 185 insertions(+), 28 deletions(-) create mode 100644 docs/object_classes.statement.ipynb diff --git a/docs/conditional_statement.ipynb b/docs/conditional_statement.ipynb index 91b1fdd..f977384 100644 --- a/docs/conditional_statement.ipynb +++ b/docs/conditional_statement.ipynb @@ -1,33 +1,5 @@ { "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "55bb0dbd", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "More\n" - ] - } - ], - "source": [ - "x = int(input(\"Please enter an integer: \"))\n", - "\n", - "if x < 0:\n", - " x = 0\n", - " print('Negative changed to zero')\n", - "elif x == 0:\n", - " print('Zero')\n", - "elif x == 1:\n", - " print('Single')\n", - "else:\n", - " print('More')" - ] - }, { "cell_type": "code", "execution_count": 3, @@ -221,6 +193,122 @@ " continue\n", " print(f\"Found an odd number {num}\")" ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "627db003", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2 is a prime number\n", + "3 is a prime number\n", + "4 equals 2 * 2\n", + "5 is a prime number\n", + "6 equals 2 * 3\n", + "7 is a prime number\n", + "8 equals 2 * 4\n", + "9 equals 3 * 3\n" + ] + } + ], + "source": [ + "for n in range(2, 10):\n", + " for x in range(2, n):\n", + " if n % x == 0:\n", + " print(n, 'equals', x, '*', n//x)\n", + " break\n", + " else:\n", + " # loop fell through without finding a factor\n", + " print(n, 'is a prime number')" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "11382f1b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I'm feeling the blues :(\n" + ] + } + ], + "source": [ + "from enum import Enum\n", + "class Color(Enum):\n", + " RED = 'red'\n", + " GREEN = 'green'\n", + " BLUE = 'blue'\n", + "\n", + "color = Color(input(\"Enter your choice of 'red', 'blue' or 'green': \"))\n", + "\n", + "match color:\n", + " case Color.RED:\n", + " print(\"I see red!\")\n", + " case Color.GREEN:\n", + " print(\"Grass is green\")\n", + " case Color.BLUE:\n", + " print(\"I'm feeling the blues :(\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "40b270a7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Shape: rectangle\n", + "Width: 4\n", + "Height: 5\n", + "Perimeter: 18\n", + "Area: 20\n" + ] + } + ], + "source": [ + "class Shape:\n", + " def __init__(self, name):\n", + " self.name = name\n", + "\n", + " def perimeter(self):\n", + " raise NotImplementedError(\"perimeter\")\n", + "\n", + " def area(self):\n", + " raise NotImplementedError(\"area\")\n", + "\n", + "class Rectangle(Shape):\n", + " def __init__(self, width, height):\n", + " super().__init__(\"rectangle\")\n", + " self.width = width\n", + " self.height = height\n", + "\n", + " def perimeter(self):\n", + " return 2 * (self.width + self.height)\n", + "\n", + " def area(self):\n", + " return self.width * self.height\n", + "\n", + "# Create a rectangle\n", + "r = Rectangle(4, 5)\n", + "\n", + "# Print results\n", + "print(\"Shape:\", r.name)\n", + "print(\"Width:\", r.width)\n", + "print(\"Height:\", r.height)\n", + "print(\"Perimeter:\", r.perimeter())\n", + "print(\"Area:\", r.area())\n" + ] } ], "metadata": { diff --git a/docs/object_classes.statement.ipynb b/docs/object_classes.statement.ipynb new file mode 100644 index 0000000..208e446 --- /dev/null +++ b/docs/object_classes.statement.ipynb @@ -0,0 +1,69 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 6, + "id": "2b55e0bd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello, my name is John Doe\n", + "Hello, my name is Peter Mary\n" + ] + } + ], + "source": [ + "class Person: \n", + " def introduction(self):\n", + " print(\"Hello, my name is \" + self.name)\n", + "\n", + "\n", + "r1 = Person()\n", + "r1.name = \"John Doe\"\n", + "r1.age = 30\n", + "r1.status = \"single\"\n", + "\n", + "\n", + "r2 = Person()\n", + "r2.name = \"Peter Mary\"\n", + "r2.age = 50\n", + "r2.status = \"married\"\n", + "\n", + "r1.introduction()\n", + "r2.introduction()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2ba1f3c6", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pythonclass", + "language": "python", + "name": "python3" + }, + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 5628673f9c68d0c1dfcb8ab456a3cf871400ca54 Mon Sep 17 00:00:00 2001 From: tomike26 Date: Mon, 7 Jul 2025 13:56:23 +0100 Subject: [PATCH 4/7] basic commands for uv and pip --- docs/uv.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/uv.md b/docs/uv.md index e69de29..0b6e25c 100644 --- a/docs/uv.md +++ b/docs/uv.md @@ -0,0 +1,19 @@ +step by step basic command for uv and pip +1. Install uv: +- irm https://astral.sh/uv/install.ps1 | iex +- uv --version (check if it is installed) + +Install PIP: +- https://bootstrap.pypa.io/get-pip.py - link to install +- python get-pip.py +- pip --version + +2. Run the command uv run python for the create environment +3. .venv\Scripts\Activate.ps1 - activate the environment +4. Install Jupyter - pip install notebook +5. jupyter notebook - to open on local host + + +using uv to install jupyter: +- uv pip install notebook +jupyter notebook - to open on local host \ No newline at end of file From 9c5ae92ba292487b1dd02f321826aad87f551e6a Mon Sep 17 00:00:00 2001 From: tomike26 Date: Thu, 10 Jul 2025 13:48:01 +0100 Subject: [PATCH 5/7] autobiograph task done --- docs/autobiograph.ipynb | 88 +++++++++++++++++++++ docs/function.ipynb | 115 ++++++++++++++++++++++++++++ docs/object_classes.statement.ipynb | 89 +++++++++++++++++---- 3 files changed, 277 insertions(+), 15 deletions(-) create mode 100644 docs/autobiograph.ipynb create mode 100644 docs/function.ipynb diff --git a/docs/autobiograph.ipynb b/docs/autobiograph.ipynb new file mode 100644 index 0000000..bb6b6f3 --- /dev/null +++ b/docs/autobiograph.ipynb @@ -0,0 +1,88 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "81881db3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hi, I’m Peter, 25 years old from Lagos.\n", + "My hobbies are: coding, reading, music.\n", + "I start my day with learning, then coding, and end with a short walk.\n", + "I am very disciplined and I work diligently.\n", + "I always look for innovative ways to solves tough problems.\n", + "Peter and Daniel are now very close buddies and share hobbies like reading, music!\n" + ] + } + ], + "source": [ + "class Disciplined:\n", + " def work_ethic(self):\n", + " return \"I am very disciplined and I work diligently.\"\n", + "\n", + "class Innovative:\n", + " def think_outside_box(self):\n", + " return \"I always look for innovative ways to solves tough problems.\"\n", + "\n", + "class MyAutobiography(Disciplined, Innovative):\n", + " def __init__(self, name, age, location, hobbies):\n", + " self.name = name\n", + " self.age = age\n", + " self.location = location\n", + " self.hobbies = hobbies\n", + "\n", + " def __add__(self, other):\n", + " if isinstance(other, MyAutobiography):\n", + " shared_hobbies = set(self.hobbies) & set(other.hobbies)\n", + " shared = ', '.join(shared_hobbies) if shared_hobbies else 'none'\n", + " return f\"{self.name} and {other.name} are now very close buddies and share hobbies like {shared}!\"\n", + " return \"I can only interact with someone like me.\"\n", + "\n", + " def introduce(self):\n", + " return f\"Hi, I’m {self.name}, {self.age} years old from {self.location}.\"\n", + "\n", + " def show_hobbies(self):\n", + " return f\"My hobbies are: {', '.join(self.hobbies)}.\"\n", + "\n", + " def daily_routine(self):\n", + " return \"I start my day with learning, then coding, and end with a short walk.\"\n", + "\n", + "me = MyAutobiography(\"Tomike\", 25, \"Ibadan\", [\"coding\", \"reading\", \"music\"])\n", + "friend = MyAutobiography(\"Philip\", 26, \"Lagos\", [\"music\", \"football\", \"reading\"])\n", + "\n", + "\n", + "print(me.introduce())\n", + "print(me.show_hobbies())\n", + "print(me.daily_routine())\n", + "print(me.work_ethic())\n", + "print(me.think_outside_box())\n", + "print(me + friend)\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pythonclass", + "language": "python", + "name": "python3" + }, + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/function.ipynb b/docs/function.ipynb new file mode 100644 index 0000000..76a6e74 --- /dev/null +++ b/docs/function.ipynb @@ -0,0 +1,115 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a1e0eded", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 4, 4, 8, 12, 20, 32, 52, 84]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def fib2(n): \n", + " \"\"\"Return a list containing the Fibonacci series up to n.\"\"\"\n", + " result = []\n", + " a, b = 0, 4\n", + " while a < n:\n", + " result.append(a) \n", + " a, b = b, a+b\n", + " return result\n", + "\n", + "f100 = fib2(100) \n", + "f100 " + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "d7ec91b9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def ask_ok(prompt, retries=4, reminder='Please try again!'):\n", + " while True:\n", + " reply = input(prompt)\n", + " if reply in {'n', 'ne', 'never'}:\n", + " return True\n", + " if reply in {'y', 'ye', 'yeah'}:\n", + " return False\n", + " retries = retries - 1\n", + " if retries < 0:\n", + " raise ValueError('invalid user response')\n", + " print(reminder)\n", + "\n", + "ask_ok(\"Do you want to continue? (yes/no): \")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "234c75c6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[6]\n", + "[6, 8]\n", + "[6, 8, 9]\n" + ] + } + ], + "source": [ + "def f(a, L=[]):\n", + " L.append(a)\n", + " return L\n", + "\n", + "print(f(6))\n", + "print(f(8))\n", + "print(f(9))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pythonclass", + "language": "python", + "name": "python3" + }, + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/object_classes.statement.ipynb b/docs/object_classes.statement.ipynb index 208e446..b15efc6 100644 --- a/docs/object_classes.statement.ipynb +++ b/docs/object_classes.statement.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "2b55e0bd", "metadata": {}, "outputs": [ @@ -10,36 +10,95 @@ "name": "stdout", "output_type": "stream", "text": [ - "Hello, my name is John Doe\n", - "Hello, my name is Peter Mary\n" + "Hello, my name is Single\n", + "Hello, my name is Married\n" + ] + } + ], + "source": [ + "class Staff: \n", + " def __init__(self,name,age,status):\n", + " self.name =name\n", + " self.age = age\n", + " self.status = status\n", + " def introduction(self):\n", + " print(\"Hello, my name is \" + self.status)\n", + "\n", + "r1 = Staff (\"Alice\", 30, \"Single\")\n", + "r2 = Staff (\"Peter\", 50, \"Married\")\n", + "r1.introduction()\n", + "r2.introduction()" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "2ba1f3c6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello, my name is Alice\n", + "Hello, my name is Peter\n", + "I am Tomike I am Soft I am currently sitting \n", + "I am Leke I am Agressive I am currently standing \n", + "Hello, my name is Peter\n", + "Hello, my name is Alice\n" ] } ], "source": [ - "class Person: \n", + "class Person :\n", + " def __init__(self,name,personality,isSitting):\n", + " self.name = name\n", + " self.personality = personality\n", + " self.isSitting = isSitting\n", + "\n", + " def introduction(self):\n", + " sittingStatus = 'sitting' if self.isSitting else 'standing'\n", + " print(f\"I am {self.name} I am {self.personality} I am currently {sittingStatus} \")\n", + "\n", + "class Staff: \n", + " def __init__(self,name,age,status):\n", + " self.name =name\n", + " self.age = age\n", + " self.status = status\n", " def introduction(self):\n", " print(\"Hello, my name is \" + self.name)\n", "\n", + "r1 = Staff (\"Alice\", 30, \"Single\")\n", + "r2 = Staff (\"Peter\", 50, \"Married\")\n", + "r1.introduction()\n", + "r2.introduction()\n", "\n", - "r1 = Person()\n", - "r1.name = \"John Doe\"\n", - "r1.age = 30\n", - "r1.status = \"single\"\n", + "p1 = Person(\"Tomike\",\"Soft\", True)\n", + "p1.introduction()\n", "\n", + "p2 = Person(\"Leke\",\"Agressive\", False)\n", + "p2.introduction()\n", "\n", - "r2 = Person()\n", - "r2.name = \"Peter Mary\"\n", - "r2.age = 50\n", - "r2.status = \"married\"\n", + "p1.Staff = r2\n", + "p1.Staff.introduction()\n", "\n", - "r1.introduction()\n", - "r2.introduction()" + "p2.Staff = r1\n", + "p2.Staff.introduction()\n", + "\n" ] }, { "cell_type": "code", "execution_count": null, - "id": "2ba1f3c6", + "id": "db3e7988", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2feba1be", "metadata": {}, "outputs": [], "source": [] From 3e839db471e00ae112847259722bcade7674de2c Mon Sep 17 00:00:00 2001 From: tomike26 Date: Thu, 10 Jul 2025 13:49:19 +0100 Subject: [PATCH 6/7] autobiograph task done --- docs/autobiograph.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/autobiograph.ipynb b/docs/autobiograph.ipynb index bb6b6f3..6a3c593 100644 --- a/docs/autobiograph.ipynb +++ b/docs/autobiograph.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "81881db3", "metadata": {}, "outputs": [ @@ -10,12 +10,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "Hi, I’m Peter, 25 years old from Lagos.\n", + "Hi, I’m Tomike, 25 years old from Ibadan.\n", "My hobbies are: coding, reading, music.\n", "I start my day with learning, then coding, and end with a short walk.\n", "I am very disciplined and I work diligently.\n", "I always look for innovative ways to solves tough problems.\n", - "Peter and Daniel are now very close buddies and share hobbies like reading, music!\n" + "Tomike and Philip are now very close buddies and share hobbies like reading, music!\n" ] } ], From 31c56de95b7b2bdf1c4ecf0630a0ccdf8d461cd0 Mon Sep 17 00:00:00 2001 From: tomike26 Date: Thu, 17 Jul 2025 02:08:14 +0100 Subject: [PATCH 7/7] DSA Python list and arrays --- docs/DSA/list_arrays.ipynb | 80 +++++++++++++++++++++++++ docs/DSA/stacks.ipynb | 120 +++++++++++++++++++++++++++++++++++++ docs/autobiograph.ipynb | 6 +- docs/lists.ipynb | 43 ++++++++++++- 4 files changed, 245 insertions(+), 4 deletions(-) create mode 100644 docs/DSA/list_arrays.ipynb create mode 100644 docs/DSA/stacks.ipynb diff --git a/docs/DSA/list_arrays.ipynb b/docs/DSA/list_arrays.ipynb new file mode 100644 index 0000000..ac6f8be --- /dev/null +++ b/docs/DSA/list_arrays.ipynb @@ -0,0 +1,80 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "id": "31fc49b3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Lowest value 4\n" + ] + } + ], + "source": [ + "list_array = [4,5,6,7,8,9]\n", + "minimumValue = list_array[0]\n", + "\n", + "for i in list_array:\n", + " if i < minimumValue:\n", + " minimumValue = i\n", + "\n", + "print('Lowest value', minimumValue)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "2d0967a0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 3, 4, 5, 5, 6, 7, 8]\n" + ] + } + ], + "source": [ + "y = [2,3,4,5,6,7,8]\n", + "y.reverse()\n", + "y.append(5)\n", + "y.sort()\n", + "print(y)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c360187d", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pythonclass", + "language": "python", + "name": "python3" + }, + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/DSA/stacks.ipynb b/docs/DSA/stacks.ipynb new file mode 100644 index 0000000..2b56b9c --- /dev/null +++ b/docs/DSA/stacks.ipynb @@ -0,0 +1,120 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 32, + "id": "02385c59", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Nigeria', 'United State', 'Canada']\n", + "Peek: Canada\n", + "pop: Canada\n", + "Size: 2\n" + ] + } + ], + "source": [ + "country = []\n", + "country.append('Nigeria')\n", + "country.append('United State')\n", + "country.append('Canada')\n", + "country.append('Germany')\n", + "country.pop()\n", + "print(country)\n", + "\n", + "countryElement = country[-1]\n", + "print (\"Peek: \", countryElement)\n", + "\n", + "countryPopElement = country.pop()\n", + "print (\"pop: \", countryPopElement)\n", + "\n", + "print (\"Size: \",len(country))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "742a4da4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Country: ['Canada', 'Alberta', 'Manitoba']\n", + "Pop: Manitoba\n", + "Peek: Alberta\n", + "Size: 2\n" + ] + } + ], + "source": [ + "class Country:\n", + " def __init__(self):\n", + " self.stack =[]\n", + "\n", + " def push(self,element):\n", + " self.stack.append(element)\n", + "\n", + " def pop(self):\n", + " if self.isEmpty():\n", + " return \"Country is empty\"\n", + " return self.stack.pop()\n", + "\n", + " def peek(self):\n", + " if self.isEmpty():\n", + " return \"Country is empty\"\n", + " return self.stack[-1]\n", + "\n", + " def isEmpty(self):\n", + " return(self.stack) == 0\n", + " def size(self):\n", + " return len(self.stack)\n", + "\n", + "\n", + "myCountry = Country()\n", + "myCountry.push('Canada')\n", + "myCountry.push('Alberta')\n", + "myCountry.push('Manitoba')\n", + "\n", + "print(\"Country:\", myCountry.stack)\n", + "print(\"Pop:\", myCountry.pop())\n", + "print(\"Peek:\", myCountry.peek())\n", + "print(\"Size:\", myCountry.size())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1cc00369", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pythonclass", + "language": "python", + "name": "python3" + }, + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/autobiograph.ipynb b/docs/autobiograph.ipynb index 6a3c593..227a3f9 100644 --- a/docs/autobiograph.ipynb +++ b/docs/autobiograph.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "id": "81881db3", "metadata": {}, "outputs": [ @@ -14,7 +14,7 @@ "My hobbies are: coding, reading, music.\n", "I start my day with learning, then coding, and end with a short walk.\n", "I am very disciplined and I work diligently.\n", - "I always look for innovative ways to solves tough problems.\n", + "I always look for various innovative ways to solves tough problems.\n", "Tomike and Philip are now very close buddies and share hobbies like reading, music!\n" ] } @@ -26,7 +26,7 @@ "\n", "class Innovative:\n", " def think_outside_box(self):\n", - " return \"I always look for innovative ways to solves tough problems.\"\n", + " return \"I always look for various innovative ways to solves tough problems.\"\n", "\n", "class MyAutobiography(Disciplined, Innovative):\n", " def __init__(self, name, age, location, hobbies):\n", diff --git a/docs/lists.ipynb b/docs/lists.ipynb index 7483444..7386824 100644 --- a/docs/lists.ipynb +++ b/docs/lists.ipynb @@ -395,9 +395,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "cb1e5983", "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Lowest value: 4\n" + ] + } + ], + "source": [ + "my_array = [7, 12, 9, 4, 11, 8]\n", + "minVal = my_array[0]\n", + "\n", + "for i in my_array:\n", + " if i < minVal:\n", + " minVal = i\n", + "\n", + "print('Lowest value:', minVal)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2bb90913", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Lowest value 2\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "95896e6c", + "metadata": {}, "outputs": [], "source": [] }