0 out of 464 challenges solved
### Problem Statement Write a Python function `angle_of_complex(real, imag)` that calculates the angle (or phase) of a complex number given its real and imaginary parts. The angle should be returned in radians. The angle of a complex number \( z = a + bi \) is defined as the angle \( \theta \) between the positive real axis and the line representing the complex number in the complex plane. This can be calculated using the `cmath.phase` function. ### Example Usage ```python [main.nopy] angle = angle_of_complex(1, 1) print(angle) # Expected output: 0.7853981633974483 (approximately π/4) angle = angle_of_complex(0, 1) print(angle) # Expected output: 1.5707963267948966 (approximately π/2) angle = angle_of_complex(-1, -1) print(angle) # Expected output: -2.356194490192345 (approximately -3π/4) ```
import cmath def angle_of_complex(real, imag): """ Calculate the angle (phase) of a complex number given its real and imaginary parts. Args: real (float): The real part of the complex number. imag (float): The imaginary part of the complex number. Returns: float: The angle (in radians) of the complex number. """ # Create the complex number from real and imaginary parts # Use cmath.phase to calculate the angle pass # Replace this with the actual implementation