Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SciProg2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pclark3
SciProg2024
Commits
9cf34261
Commit
9cf34261
authored
1 year ago
by
cprutean
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
805618f7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CodeExamples/ComplexQuadrant.ipynb
+74
-0
74 additions, 0 deletions
CodeExamples/ComplexQuadrant.ipynb
with
74 additions
and
0 deletions
CodeExamples/ComplexQuadrant.ipynb
0 → 100644
+
74
−
0
View file @
9cf34261
{
"cells": [
{
"cell_type": "markdown",
"id": "1d2b1bb3",
"metadata": {},
"source": [
"# Complex Quadrant"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19d70e52",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
" Program to read in a complex number and print out which \n",
" quadrant it is in using a if: elif chain inside a function\n",
"\"\"\"\n",
"\n",
"import cmath # Add complex maths libary\n",
"\n",
"def quadrant(z):\n",
" \"\"\"\n",
" Function to determine which quadrant a complex number is in.\n",
" \"\"\"\n",
" if z.real >= 0 and z.imag >= 0 :\n",
" return 1\n",
"\n",
" elif z.real < 0 and z.imag >= 0 :\n",
" return 2\n",
"\n",
" elif z.real < 0 and z.imag < 0 :\n",
" return 3\n",
"\n",
" else:\n",
" return 4\n",
"\n",
" \n",
"\n",
"def main():\n",
" z = complex(input(\"Give a complex number : \"))\n",
" print(\"Typed number is : \" + str(z))\n",
" # We are able to just use the fuction inside the str()\n",
" print(\"It is in quadrant : \" + str(quadrant(z)))\n",
"\n",
"main()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:markdown id:1d2b1bb3 tags:
# Complex Quadrant
%% Cell type:code id:19d70e52 tags:
```
python
"""
Program to read in a complex number and print out which
quadrant it is in using a if: elif chain inside a function
"""
import
cmath
# Add complex maths libary
def
quadrant
(
z
):
"""
Function to determine which quadrant a complex number is in.
"""
if
z
.
real
>=
0
and
z
.
imag
>=
0
:
return
1
elif
z
.
real
<
0
and
z
.
imag
>=
0
:
return
2
elif
z
.
real
<
0
and
z
.
imag
<
0
:
return
3
else
:
return
4
def
main
():
z
=
complex
(
input
(
"
Give a complex number :
"
))
print
(
"
Typed number is :
"
+
str
(
z
))
# We are able to just use the fuction inside the str()
print
(
"
It is in quadrant :
"
+
str
(
quadrant
(
z
)))
main
()
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment