#! /usr/bin/env python # -*- coding: utf8 -*- """ Solution for exercise #5 of the 3rd week lab @ MEC 2015.""" print "Example with complex numbers." z = input("Please give me a complex number (in the form a+bj -- warning it is a j and not a i) : z = ") print "Real(z) =", z.real print "Im(z) =", z.imag print "|z| =", abs(z) # Here is something new! from cmath import phase # cmath is maths functions for complex numbers print "Arg(z) =", phase(z) # The bonus question is longer if z == 0: print "z = 0" elif z.real == 0: print "z is pure imaginary" elif z.imag == 0: print "z is pure real" elif z.real > 0 and z.imag > 0: print "z is in the first quadrant" elif z.real < 0 and z.imag > 0: print "z is in the second quadrant" elif z.real < 0 and z.imag < 0: print "z is in the third quadrant" else: print "z is in the forth quadrant"