Complete the code to calculate the sine of 0 radians using numpy.
import numpy as np result = np.[1](0) print(result)
The sin function calculates the sine of an angle in radians. Here, np.sin(0) returns 0.
Complete the code to calculate the cosine of pi radians using numpy.
import numpy as np result = np.[1](np.pi) print(result)
The cosine of pi radians is -1. Using np.cos(np.pi) calculates this value.
Fix the error in the code to calculate the tangent of 45 degrees using numpy. (Hint: numpy expects radians.)
import numpy as np angle_degrees = 45 angle_radians = angle_degrees [1] np.pi / 180 result = np.tan(angle_radians) print(result)
To convert degrees to radians, multiply degrees by pi and divide by 180. The correct formula is angle_degrees * np.pi / 180, which is equivalent to angle_degrees / 180 * np.pi. The blank should be '/'.
Fill both blanks to create a dictionary that maps angles in degrees to their sine values using numpy.
import numpy as np angles = [0, 30, 45, 60, 90] sine_values = {angle: np.sin(angle [1] np.pi / 180) for angle in [2] print(sine_values)
To convert degrees to radians inside the dictionary comprehension, multiply the angle by pi and divide by 180. The list to iterate over is angles.
Fill both blanks to create a dictionary that maps angles in degrees to their cosine values, but only include angles where cosine is greater than 0.5.
import numpy as np angles = [0, 30, 45, 60, 90] cosine_values = {angle: np.[1](angle * np.pi / 180) for angle in angles if np.cos(angle * np.pi / 180) [2] 0.5} print(cosine_values)
The dictionary key is just angle, so no extra symbol is needed (empty string). The function to calculate cosine is cos. The condition filters angles where cosine is greater than 0.5, so the operator is >.