Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Group_1/GROUP 1 NAMES.docx
Binary file not shown.
Binary file added Group_1/GROUP_1 REPORT.docx
Binary file not shown.
134 changes: 134 additions & 0 deletions Group_1/Group_1 code.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
Binary file added Group_1/Group_1 flowchart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.