Polar Coordinates

Sort by

recency

|

470 Discussions

|

  • + 0 comments
    1. import cmath
      1. n = input()
    2. complex_no = complex(n)
    3. real_part = complex_no.real
    4. imaginary_part = complex_no.imag
    5. print(abs(complex(imaginary_part,real_part)))
    6. print(cmath.phase(complex(real_part,imaginary_part)))
  • [deleted]Challenge Author
    + 0 comments

    For Python3

    import cmath
    
    c = complex(input())
    
    print(abs(c))
    print(cmath.phase(c))
    
  • + 1 comment
    from math import sqrt,atan,pi
    
    z=complex(input())
    
    x=z.real 
    y=z.imag 
    
    r=sqrt(x**2+y**2)
    
    if x<0 and y>=0:
        theta=atan(y/x)+pi
    elif x<0 and y<0:
        theta=atan(y/x)-pi
    elif x>0 and y<0:
        theta=atan(y/x)
    elif x>0 and y>=0:
        theta=atan(y/x)
    elif x==0 and y>0:
        theta=pi/2
    elif x==0 and y<0:
        theta=-pi/2
    else:
        theta=0
    
    print(f'{r}\n{theta}')
    
  • + 1 comment

    In barely few lines...

    import cmath
    complex_num = complex(input())
    print(abs(complex_num))
    print(cmath.phase(complex_num))
    
  • + 0 comments
    from cmath import phase
    z = input()
    print(abs(complex(z)), phase(complex(z)), sep='\n')