summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhongheng Liu <z.liu@outlook.com.gr>2025-02-19 09:43:52 +0200
committerZhongheng Liu <z.liu@outlook.com.gr>2025-02-19 09:43:52 +0200
commit8834da60a01294fd509c7cebf3b129fcc378d152 (patch)
treea1c6c4bd71e95780f87d35240754c5b54d3042ae
parent34bd7099d27656b4454015b0c410ca1713db5271 (diff)
downloadcs-y13-8834da60a01294fd509c7cebf3b129fcc378d152.tar.gz
cs-y13-8834da60a01294fd509c7cebf3b129fcc378d152.tar.bz2
cs-y13-8834da60a01294fd509c7cebf3b129fcc378d152.zip
chore: changing to ipynb
-rw-r--r--_legacy/adt-queue/queue.py (renamed from adt-queue/queue.py)0
-rw-r--r--_legacy/adt-stack/stack.py (renamed from adt-stack/stack.py)0
-rw-r--r--_legacy/algorithms/binary_sort.py (renamed from algorithms/binary_sort.py)0
-rw-r--r--_legacy/algorithms/bubble_sort.py (renamed from algorithms/bubble_sort.py)0
-rw-r--r--_legacy/algorithms/linear_search.py (renamed from algorithms/linear_search.py)0
-rw-r--r--_legacy/car.py (renamed from car.py)0
-rw-r--r--_legacy/custom/polynomial.py (renamed from custom/polynomial.py)0
-rw-r--r--_legacy/dictionaries/dicts.py (renamed from dictionaries/dicts.py)0
-rw-r--r--_legacy/hw/activity20h.py (renamed from hw/activity20h.py)0
-rw-r--r--_legacy/linked_list/linked.py (renamed from linked_list/linked.py)0
-rw-r--r--_legacy/linked_list/linked_list.py (renamed from linked_list/linked_list.py)0
-rw-r--r--_legacy/main.py (renamed from main.py)0
-rw-r--r--_legacy/oop/oop.py (renamed from oop/oop.py)62
-rw-r--r--_legacy/oop/oop2.py (renamed from oop/oop2.py)0
-rw-r--r--_legacy/oop/paper-practices/q6b.py (renamed from oop/paper-practices/q6b.py)0
-rw-r--r--_legacy/py-class.py (renamed from py-class.py)0
-rw-r--r--devenv.nix5
-rw-r--r--notebooks/data_structures.ipynb121
-rw-r--r--notebooks/dictionaries.ipynb0
-rw-r--r--notebooks/linked_lists.ipynb0
-rw-r--r--notebooks/oop.ipynb0
-rw-r--r--notebooks/recursion.ipynb158
-rw-r--r--notebooks/sorting_algorithms.ipynb201
-rw-r--r--py_test_example.py7
-rw-r--r--recursion/recursion.py51
25 files changed, 515 insertions, 90 deletions
diff --git a/adt-queue/queue.py b/_legacy/adt-queue/queue.py
index 98297b3..98297b3 100644
--- a/adt-queue/queue.py
+++ b/_legacy/adt-queue/queue.py
diff --git a/adt-stack/stack.py b/_legacy/adt-stack/stack.py
index e99f231..e99f231 100644
--- a/adt-stack/stack.py
+++ b/_legacy/adt-stack/stack.py
diff --git a/algorithms/binary_sort.py b/_legacy/algorithms/binary_sort.py
index 2e71b52..2e71b52 100644
--- a/algorithms/binary_sort.py
+++ b/_legacy/algorithms/binary_sort.py
diff --git a/algorithms/bubble_sort.py b/_legacy/algorithms/bubble_sort.py
index f77ea08..f77ea08 100644
--- a/algorithms/bubble_sort.py
+++ b/_legacy/algorithms/bubble_sort.py
diff --git a/algorithms/linear_search.py b/_legacy/algorithms/linear_search.py
index ae198d2..ae198d2 100644
--- a/algorithms/linear_search.py
+++ b/_legacy/algorithms/linear_search.py
diff --git a/car.py b/_legacy/car.py
index 4104b42..4104b42 100644
--- a/car.py
+++ b/_legacy/car.py
diff --git a/custom/polynomial.py b/_legacy/custom/polynomial.py
index ce0bbd8..ce0bbd8 100644
--- a/custom/polynomial.py
+++ b/_legacy/custom/polynomial.py
diff --git a/dictionaries/dicts.py b/_legacy/dictionaries/dicts.py
index 47a79e8..47a79e8 100644
--- a/dictionaries/dicts.py
+++ b/_legacy/dictionaries/dicts.py
diff --git a/hw/activity20h.py b/_legacy/hw/activity20h.py
index 8bf0319..8bf0319 100644
--- a/hw/activity20h.py
+++ b/_legacy/hw/activity20h.py
diff --git a/linked_list/linked.py b/_legacy/linked_list/linked.py
index d3f0084..d3f0084 100644
--- a/linked_list/linked.py
+++ b/_legacy/linked_list/linked.py
diff --git a/linked_list/linked_list.py b/_legacy/linked_list/linked_list.py
index 4c07536..4c07536 100644
--- a/linked_list/linked_list.py
+++ b/_legacy/linked_list/linked_list.py
diff --git a/main.py b/_legacy/main.py
index e69de29..e69de29 100644
--- a/main.py
+++ b/_legacy/main.py
diff --git a/oop/oop.py b/_legacy/oop/oop.py
index 4ef15d7..65c79f0 100644
--- a/oop/oop.py
+++ b/_legacy/oop/oop.py
@@ -1,32 +1,32 @@
-import math
-class shape:
- def __init__(self):
- pass
- def area(self):
- pass
-class circle(shape):
- def __init__(self, r):
- shape.__init__(self)
- self._radius = r
- def area(self):
- return self._radius * self._radius * math.pi
-class rectangle(shape):
- def __init__(self, side1, side2):
- shape.__init__(self)
- self._a = side1
- self._b = side2
- def area(self):
- return self._a * self._b
-class square(shape):
- def __init__(self, side):
- shape.__init__(self)
- self._side = side
- def area(self):
- return self._side ** 2
-
-sq = square(4)
-cir = circle(7)
-rect = rectangle(3,6)
-print(sq.area())
-print(cir.area())
+import math
+class shape:
+ def __init__(self):
+ pass
+ def area(self):
+ pass
+class circle(shape):
+ def __init__(self, r):
+ shape.__init__(self)
+ self._radius = r
+ def area(self):
+ return self._radius * self._radius * math.pi
+class rectangle(shape):
+ def __init__(self, side1, side2):
+ shape.__init__(self)
+ self._a = side1
+ self._b = side2
+ def area(self):
+ return self._a * self._b
+class square(shape):
+ def __init__(self, side):
+ shape.__init__(self)
+ self._side = side
+ def area(self):
+ return self._side ** 2
+
+sq = square(4)
+cir = circle(7)
+rect = rectangle(3,6)
+print(sq.area())
+print(cir.area())
print(rect.area()) \ No newline at end of file
diff --git a/oop/oop2.py b/_legacy/oop/oop2.py
index f764420..f764420 100644
--- a/oop/oop2.py
+++ b/_legacy/oop/oop2.py
diff --git a/oop/paper-practices/q6b.py b/_legacy/oop/paper-practices/q6b.py
index 90ebd89..90ebd89 100644
--- a/oop/paper-practices/q6b.py
+++ b/_legacy/oop/paper-practices/q6b.py
diff --git a/py-class.py b/_legacy/py-class.py
index c4eec79..c4eec79 100644
--- a/py-class.py
+++ b/_legacy/py-class.py
diff --git a/devenv.nix b/devenv.nix
index f208755..341a56e 100644
--- a/devenv.nix
+++ b/devenv.nix
@@ -9,7 +9,10 @@
# https://devenv.sh/languages/
# languages.rust.enable = true;
- languages.python.enable = true;
+ languages.python = {
+ enable = true;
+ venv.enable = true;
+ };
# https://devenv.sh/processes/
# processes.cargo-watch.exec = "cargo-watch";
diff --git a/notebooks/data_structures.ipynb b/notebooks/data_structures.ipynb
new file mode 100644
index 0000000..f116cf5
--- /dev/null
+++ b/notebooks/data_structures.ipynb
@@ -0,0 +1,121 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# ADT - Stack\n",
+ "Push and pop methods."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "stack = [None for index in range(0,10)]\n",
+ "basePointer = 0\n",
+ "topPointer = -1\n",
+ "stackFull = 10\n",
+ "\n",
+ "def push(item):\n",
+ " global stack, topPointer\n",
+ " topPointer += 1\n",
+ " if topPointer >= stackFull: \n",
+ " print(\"ERROR Cannot insert more.\")\n",
+ " return\n",
+ " stack[topPointer] = item\n",
+ " print(stack)\n",
+ "def pop():\n",
+ " global stack, topPointer\n",
+ " if topPointer < basePointer:\n",
+ " print(\"ERROR List is empty, cannot pop.\")\n",
+ " return\n",
+ " itemPopped = stack[topPointer]\n",
+ " print(f\"I popped this {itemPopped}\")\n",
+ " stack[topPointer] = None\n",
+ " topPointer -= 1\n",
+ " print(stack)\n",
+ "def test():\n",
+ " push(1)\n",
+ " push(2)\n",
+ " push(69)\n",
+ "\n",
+ " pop()\n",
+ " pop()\n",
+ "\n",
+ " print(stack)\n",
+ "\n",
+ " pop()\n",
+ " pop()\n",
+ "\n",
+ "test()\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# ADT - Queue\n",
+ "Enqueue and dequeue methods."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "queue = [None for index in range(0, 10)]\n",
+ "frontPointer = 0\n",
+ "rearPointer = -1\n",
+ "queueLength = 0\n",
+ "queueFull = 10\n",
+ "def dequeue():\n",
+ " global queue, queueLength, queueFull, rearPointer, frontPointer\n",
+ " if queueLength == 0:\n",
+ " print(\"ERR:: Cannot dequeue an empty queue!\") \n",
+ " return\n",
+ " item = queue[frontPointer]\n",
+ " queue[frontPointer] = None\n",
+ " frontPointer += 1\n",
+ " print(f\"Dequeued element {item}\")\n",
+ " return\n",
+ " \n",
+ "def enqueue(item):\n",
+ " global queue, queueLength, queueFull, rearPointer\n",
+ " if queueLength < queueFull:\n",
+ " if rearPointer < len(queue) - 1:\n",
+ " rearPointer += 1\n",
+ " else:\n",
+ " rearPointer = 0\n",
+ " queueLength += 1\n",
+ " queue[rearPointer] = item\n",
+ " print(queue)\n",
+ " return\n",
+ " print(\"ERROR queue length exceeded!\")\n",
+ " return\n",
+ "for i in range(13):\n",
+ " enqueue(10 * i)\n",
+ "dequeue()\n",
+ "dequeue()\n",
+ "dequeue()\n",
+ "print(queue)\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": ".venv",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "name": "python",
+ "version": "3.12.8"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/notebooks/dictionaries.ipynb b/notebooks/dictionaries.ipynb
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/notebooks/dictionaries.ipynb
diff --git a/notebooks/linked_lists.ipynb b/notebooks/linked_lists.ipynb
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/notebooks/linked_lists.ipynb
diff --git a/notebooks/oop.ipynb b/notebooks/oop.ipynb
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/notebooks/oop.ipynb
diff --git a/notebooks/recursion.ipynb b/notebooks/recursion.ipynb
new file mode 100644
index 0000000..9474acf
--- /dev/null
+++ b/notebooks/recursion.ipynb
@@ -0,0 +1,158 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Recursion\n",
+ "Practices on recursion for Year 13 Computer Science."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Practice - outputs the binary representation of number recursively.\n",
+ "def x(n: int):\n",
+ " if ( n == 0 ) or ( n == 1 ):\n",
+ " print(n, end=\"\")\n",
+ " return\n",
+ " x(n // 2)\n",
+ " print(n % 2, end=\"\")\n",
+ "def rec_bin(n: int):\n",
+ " x(n)\n",
+ " print()\n",
+ "for i in range(0, 16):\n",
+ " rec_bin(i)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def fact(n: int): return n * fact(n-1) if n != 0 else 1\n",
+ "\n",
+ "def compound(p: float, r: float, y: int) -> float:\n",
+ " return p if y == 0 else compound(p*r, r, y-1)\n",
+ "\n",
+ "def print_fib(a, b, l):\n",
+ " print(a)\n",
+ " print(b)\n",
+ " print_next_fib(a, b, l-3)\n",
+ "\n",
+ "def print_next_fib(a: int, b: int, l: int):\n",
+ " if l == 0:\n",
+ " print(a+b)\n",
+ " return\n",
+ " print(a+b)\n",
+ " return print_next_fib(b, a+b, l-1)\n",
+ "\n",
+ "def fib_nth(n: int):\n",
+ " if n == 1:\n",
+ " return 0\n",
+ " if n == 2:\n",
+ " return 1\n",
+ " return fib_nth(n-1) + fib_nth(n-2)\n",
+ "\n",
+ "def draw_underline(l: int):\n",
+ " return '-'*l\n",
+ "\n",
+ "def test():\n",
+ " range_end = 15\n",
+ " print(f\"Printing series of factorials from 1 to {range_end}\\n{draw_underline(20)}\")\n",
+ " for i in range(1, range_end):\n",
+ " print(fact(i), end=\", \" if i < range_end-1 else \"\\n\")\n",
+ " fib_until = 15\n",
+ " print(f\"\\n\\nPrinting fibonacci sequence to {fib_until}\\n{draw_underline(20)}\")\n",
+ " print_fib(0, 1, fib_until)\n",
+ " print(fib_nth(5))\n",
+ " print(compound(36800*4, 1.06, 10) / (43129-3170*12))\n",
+ "def payback(tuition: int, rate: int, salary: int):\n",
+ " years = 0\n",
+ " remaining = tuition * 4\n",
+ "\n",
+ " while remaining > 0:\n",
+ " remaining -= salary\n",
+ " years += 1\n",
+ " remaining *= rate\n",
+ " print(f\"Year {years}: remaining: {remaining}\")\n",
+ " print(years)\n",
+ "\n",
+ "if __name__ == \"__main__\":\n",
+ " test()\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Object-oriented programming"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "class Student: \n",
+ " def __init__(self, name: str, dateOfBirth: str, examMark: int):\n",
+ " self.__name = name\n",
+ " self.__dateOfBirth = dateOfBirth\n",
+ " self.__examMark = examMark\n",
+ " def displayExamMark(self):\n",
+ " print(f\"{self.__name} got {self.__examMark} marks\")\n",
+ "\n",
+ "\n",
+ "class PartTimeStudent(Student):\n",
+ " def __init__(self, name: str, dateOfBirth: str, examMark: int):\n",
+ " self.__isFullTime = False\n",
+ " super().__init__(name, dateOfBirth, examMark)\n",
+ " def time(self):\n",
+ " return \"Full time\" if self.__isFullTime else \"Part time\"\n",
+ "\n",
+ "\n",
+ "class FullTimeStudent(Student):\n",
+ " def __init__(self, name: str, dateOfBirth: str, examMark: int):\n",
+ " self.__isFullTime = True\n",
+ " super().__init__(name, dateOfBirth, examMark)\n",
+ " def time(self):\n",
+ " return \"Full time\" if self.__isFullTime else \"Part time\"\n",
+ "\n",
+ "\n",
+ "myStudent = Student(\"Example Exampleperson\", \"1989-06-04\", 69)\n",
+ "myStudent.displayExamMark()\n",
+ "myFullStudent = FullTimeStudent(\"Dwayne Johnson\", \"1999-9-9\", 80)\n",
+ "myPartStudent = PartTimeStudent(\"Jake Paul\", \"1999-9-9\", 0)\n",
+ "myPartStudent.displayExamMark()\n",
+ "myFullStudent.displayExamMark()\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": ".venv",
+ "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.12.8"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/notebooks/sorting_algorithms.ipynb b/notebooks/sorting_algorithms.ipynb
new file mode 100644
index 0000000..2e6326d
--- /dev/null
+++ b/notebooks/sorting_algorithms.ipynb
@@ -0,0 +1,201 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import random\n",
+ "def generate_test_data(length: int, _range: tuple):\n",
+ " arr = []\n",
+ " for i in range(length):\n",
+ " arr.append(random.randint(int(_range[0]), int(_range[1])))\n",
+ " return arr\n",
+ "def binsearch(arr, item):\n",
+ " arr = sorted(arr)\n",
+ " print(arr)\n",
+ " ubound, lbound = len(arr) - 1, 0\n",
+ " found = False\n",
+ " while not found and lbound <= ubound:\n",
+ " index = (lbound + ubound) // 2\n",
+ " if arr[index] == item: \n",
+ " found = True\n",
+ " print(\"Found here\")\n",
+ " return found\n",
+ " if arr[index] > item:\n",
+ " ubound = index - 1\n",
+ " if arr[index] < item:\n",
+ " lbound = index + 1\n",
+ " print(\"not found\")\n",
+ " return found\n",
+ "\n",
+ "\n",
+ "def linear_search_while(arr: list, item):\n",
+ " found: bool = False\n",
+ " index = 0\n",
+ " while not found and index < len(arr):\n",
+ " if (arr[index] == item): \n",
+ " found = True\n",
+ " break\n",
+ " index += 1\n",
+ " return (found, index)\n",
+ "def linear_search(arr: list, item):\n",
+ " index = 0\n",
+ " for _item in arr:\n",
+ " if _item == item:\n",
+ " return (True, index) \n",
+ " index += 1\n",
+ " return False\n",
+ "def test_existsness(samples: int):\n",
+ " yes = 0\n",
+ " no = 0\n",
+ " for i in range(samples):\n",
+ " query = random.randint(0, 100)\n",
+ " array = generate_test_data(100, (0, 100))\n",
+ " found = linear_search(array, query)\n",
+ " if found:\n",
+ " yes += 1 \n",
+ " else:\n",
+ " no += 1\n",
+ " print(f\"In {samples} samples, {yes} match, {no} don't\")\n",
+ "def main():\n",
+ " narr = sorted([\"A\", \"B\", \"C\", \"D\", \"E\"])\n",
+ " print(\"Hello world\")\n",
+ " array = generate_test_data(10, (0, 100))\n",
+ " print(array)\n",
+ " query = int(input(\"Your query for item: \"))\n",
+ " qstring = input(\"String item: \")\n",
+ " binsearch(narr, query)\n",
+ " found1 = linear_search(array, query)\n",
+ " found2 = linear_search_while(array, query)\n",
+ " if found1[0]:\n",
+ " print(\"Found by for loop method \", found1[1]) \n",
+ " else: print(\"Not found.\")\n",
+ " if found2[0]:\n",
+ " print(\"Found by while loop method \", found2[1])\n",
+ " else: \n",
+ " print(\"Not found.\")\n",
+ " test_existsness(100)\n",
+ "if __name__ == \"__main__\":\n",
+ " main()\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n",
+ "100 checks passed!\n",
+ "['qibuvxrvcf', 'nmbxubyowk', 'ntszdjhhwf', 'xhjsoifdno', 'kbdwllyfmo', 'ndmngppihm', 'footfyjpfd', 'ridhoqmalu', 'nxlubshvcj', 'fjnnntfxur']\n",
+ "['fjnnntfxur', 'footfyjpfd', 'kbdwllyfmo', 'ndmngppihm', 'nmbxubyowk', 'ntszdjhhwf', 'nxlubshvcj', 'qibuvxrvcf', 'ridhoqmalu', 'xhjsoifdno']\n"
+ ]
+ }
+ ],
+ "source": [
+ "import random\n",
+ "import string\n",
+ "CHARS = list(string.ascii_lowercase)\n",
+ "print(CHARS)\n",
+ "def generate_test_data(length: int, _range: tuple):\n",
+ " arr = []\n",
+ " for i in range(length):\n",
+ " arr.append(random.randint(_range[0], _range[1]))\n",
+ " return arr\n",
+ "def bubsort(arr: list):\n",
+ " for i in range(len(arr)):\n",
+ " # print(arr)\n",
+ " changed = False\n",
+ " for j in range(len(arr) - i - 1):\n",
+ " if arr[j] > arr[j+1]:\n",
+ " swp = arr[j+1]\n",
+ " arr[j+1] = arr[j]\n",
+ " arr[j] = swp\n",
+ " changed = True\n",
+ " if not changed: return arr \n",
+ "def testarr_string(length: int):\n",
+ " arr = []\n",
+ " for i in range(length):\n",
+ " string = \"\"\n",
+ " for i in range(10):\n",
+ " string += CHARS[random.randint(0,len(CHARS) - 1)]\n",
+ " arr.append(string)\n",
+ " print(arr)\n",
+ " return arr\n",
+ "def bubsort_reliability(samples: int):\n",
+ " y = 0\n",
+ " n = 0\n",
+ " for _ in range(samples):\n",
+ " test = generate_test_data(100, (0, 100))\n",
+ " if bubsort(test) == sorted(test): y += 1\n",
+ " else: n += 1\n",
+ " if y == samples: print(f\"{samples} checks passed!\")\n",
+ "bubsort_reliability(100)\n",
+ "print(bubsort(testarr_string(10)))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "OH NO ITEM NOT FOUND IN LIST!!\n"
+ ]
+ }
+ ],
+ "source": [
+ "import random\n",
+ "def generate_test_data(length: int, _range: tuple):\n",
+ " arr = []\n",
+ " for i in range(length):\n",
+ " arr.append(random.randint(_range[0], _range[1]))\n",
+ " return arr\n",
+ "def linsearch(myList: list, valueToFind: int):\n",
+ " mindex: int = len(myList) - 1\n",
+ " index: int = 0\n",
+ " found = False\n",
+ " while not found and index <= mindex:\n",
+ " if myList[index] == valueToFind:\n",
+ " found = True\n",
+ " index += 1\n",
+ " if found: print(\"VALUE FOUND!!!\")\n",
+ " else: print(\"OH NO ITEM NOT FOUND IN LIST!!\")\n",
+ "def main():\n",
+ " inputFind = int(input(\"Value to find: \"))\n",
+ " linsearch(generate_test_data(10, (0, 1000)), inputFind)\n",
+ "if __name__ == \"__main__\":\n",
+ " main()\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": ".venv",
+ "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.12.8"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/py_test_example.py b/py_test_example.py
deleted file mode 100644
index 3386a11..0000000
--- a/py_test_example.py
+++ /dev/null
@@ -1,7 +0,0 @@
-def x(n: int):
- if ( n == 0 ) or ( n == 1 ):
- print(n, end="")
- return
- x(n // 2)
- print(n % 2, end="")
-x(255)
diff --git a/recursion/recursion.py b/recursion/recursion.py
deleted file mode 100644
index f46be80..0000000
--- a/recursion/recursion.py
+++ /dev/null
@@ -1,51 +0,0 @@
-def fact(n: int): return n * fact(n-1) if n != 0 else 1
-
-def compound(p: float, r: float, y: int) -> float:
- return p if y == 0 else compound(p*r, r, y-1)
-
-def print_fib(a, b, l):
- print(a)
- print(b)
- print_next_fib(a, b, l-3)
-
-def print_next_fib(a: int, b: int, l: int):
- if l == 0:
- print(a+b)
- return
- print(a+b)
- return print_next_fib(b, a+b, l-1)
-
-def fib_nth(n: int):
- if n == 1:
- return 0
- if n == 2:
- return 1
- return fib_nth(n-1) + fib_nth(n-2)
-
-def draw_underline(l: int):
- return '-'*l
-
-def test():
- range_end = 15
- print(f"Printing series of factorials from 1 to {range_end}\n{draw_underline(20)}")
- for i in range(1, range_end):
- print(fact(i), end=", " if i < range_end-1 else "\n")
- fib_until = 15
- print(f"\n\nPrinting fibonacci sequence to {fib_until}\n{draw_underline(20)}")
- print_fib(0, 1, fib_until)
- print(fib_nth(5))
- print(compound(36800*4, 1.06, 10) / (43129-3170*12))
-def payback(tuition: int, rate: int, salary: int):
- years = 0
- remaining = tuition * 4
-
- while remaining > 0:
- remaining -= salary
- years += 1
- remaining *= rate
- print(f"Year {years}: remaining: {remaining}")
- print(years)
-
-if __name__ == "__main__":
- test()
-