diff --git a/Group_1/GROUP 1 NAMES.docx b/Group_1/GROUP 1 NAMES.docx new file mode 100644 index 0000000..ae4978f Binary files /dev/null and b/Group_1/GROUP 1 NAMES.docx differ diff --git a/Group_1/GROUP_1 REPORT.docx b/Group_1/GROUP_1 REPORT.docx new file mode 100644 index 0000000..50f5455 Binary files /dev/null and b/Group_1/GROUP_1 REPORT.docx differ diff --git a/Group_1/Group_1 code.ipynb b/Group_1/Group_1 code.ipynb new file mode 100644 index 0000000..07c1553 --- /dev/null +++ b/Group_1/Group_1 code.ipynb @@ -0,0 +1,134 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "eb88a92a", + "metadata": {}, + "outputs": [], + "source": [ + "import cmath" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "3c13341c", + "metadata": {}, + "outputs": [], + "source": [ + "a = float(input(\"Enter cofficient of a \"))\n", + "b = float(input(\"Enter cofficient of b \"))\n", + "c = float(input(\"Enter cofficient of c \"))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "7cd822f7", + "metadata": {}, + "outputs": [], + "source": [ + "d = b**2 - 4*a*c" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "c5c831ad", + "metadata": {}, + "outputs": [], + "source": [ + "root1 = (- b + cmath.sqrt (d) / 2*a)\n", + "root2 = (- b - cmath.sqrt (d) / 2*a)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "5b5d555a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The root is complex\n", + "X1 = (-2+1.4142135623730951j)\n", + "X1 = (-2+1.4142135623730951j)\n" + ] + } + ], + "source": [ + "if d >= 0:\n", + " print(\"The root is real\")\n", + " print(\"X1 = \", root1.real)\n", + " print(\"X1 = \", root1.real)\n", + "else :\n", + " print(\"The root is complex\")\n", + " print(\"X1 = \", root1)\n", + " print(\"X1 = \", root1) " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "c027991b", + "metadata": {}, + "outputs": [], + "source": [ + "import pytest\n", + "import cmath\n", + "\n", + "def solve_quadratic(a, b, c):\n", + " if a == 0:\n", + " raise ValueError(\"Cofficient 'a' can not be 0\")\n", + " d = b**2 - 4*a*c\n", + " root1 = (-b + cmath.sqrt(d)) / (2*a)\n", + " root2 = (-b - cmath.sqrt(d)) / (2*a)\n", + " return d, root1, root2\n", + "\n", + "def test_real_roots():\n", + " a, b, c = 1, -3, 2 # roots: 2 and 1\n", + " d, root1, root2 = solve_quadratic(a, b, c)\n", + " assert d == 1\n", + " assert root1.real == 2\n", + " assert root2.real == 1\n", + " assert root1.imag == 0\n", + " assert root2.imag == 0\n", + "\n", + "def test_complex_roots():\n", + " a, b, c = 1, 2, 3 # roots: complex\n", + " d, root1, root2 = solve_quadratic(a, b, c)\n", + " assert d == -8\n", + " assert root1 == complex(-1, cmath.sqrt(8).real/2)\n", + " assert root2 == complex(-1, -cmath.sqrt(8).real/2)\n", + "\n", + "def test_a_zero():\n", + " with pytest.raises(ValueError):\n", + " solve_quadratic(0, 2, 3)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Group_1/Group_1 flowchart.png b/Group_1/Group_1 flowchart.png new file mode 100644 index 0000000..1131d74 Binary files /dev/null and b/Group_1/Group_1 flowchart.png differ