0 out of 464 challenges solved
Write a Python function `polar_to_rectangular(r, theta)` that converts polar coordinates to rectangular coordinates. The function should take two arguments: - `r`: The radial distance (a non-negative float). - `theta`: The angle in radians (a float). The function should return a tuple `(x, y)` representing the rectangular coordinates. #### Example Usage ```python [main.nopy] polar_to_rectangular(5, 0) # Expected output: (5.0, 0.0) polar_to_rectangular(3, 3.14159) # Expected output: (-3.0, 0.0) polar_to_rectangular(2, 1.5708) # Expected output: (0.0, 2.0) ``` #### Notes - Use the `math` module for trigonometric calculations. - Ensure the output values are rounded to two decimal places.
import math
def polar_to_rectangular(r, theta):
"""
Convert polar coordinates to rectangular coordinates.
Parameters:
r (float): Radial distance.
theta (float): Angle in radians.
Returns:
tuple: Rectangular coordinates (x, y).
"""
# Calculate x and y using trigonometric functions
# Replace the following with the correct implementation
x = None
y = None
return (x, y)