Skip to content
Snippets Groups Projects
Commit 9cf34261 authored by cprutean's avatar cprutean
Browse files

Upload New File

parent 805618f7
No related branches found
No related tags found
No related merge requests found
%% 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()
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment