0
0
NumPydata~10 mins

Trigonometric functions (sin, cos, tan) in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the sine of 0 radians using numpy.

NumPy
import numpy as np
result = np.[1](0)
print(result)
Drag options to blanks, or click blank then click option'
Acos
Barcsin
Ctan
Dsin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cos' instead of 'sin' will calculate cosine, not sine.
Using 'tan' will calculate tangent, which is different.
Using 'arcsin' is the inverse sine function, not sine.
2fill in blank
medium

Complete the code to calculate the cosine of pi radians using numpy.

NumPy
import numpy as np
result = np.[1](np.pi)
print(result)
Drag options to blanks, or click blank then click option'
Asin
Btan
Ccos
Darccos
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sin' will calculate sine, which is 0 at pi radians.
Using 'tan' will calculate tangent, which is 0 at pi radians.
Using 'arccos' is the inverse cosine function, not cosine.
3fill in blank
hard

Fix the error in the code to calculate the tangent of 45 degrees using numpy. (Hint: numpy expects radians.)

NumPy
import numpy as np
angle_degrees = 45
angle_radians = angle_degrees [1] np.pi / 180
result = np.tan(angle_radians)
print(result)
Drag options to blanks, or click blank then click option'
A*
B/
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' instead of '/' changes the formula incorrectly.
Using '+' or '-' will cause syntax or logic errors.
4fill in blank
hard

Fill both blanks to create a dictionary that maps angles in degrees to their sine values using numpy.

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)
Drag options to blanks, or click blank then click option'
A*
B+
Cangles
Drange(5)
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' in the conversion formula.
Using 'range(5)' instead of the actual list of angles.
5fill in blank
hard

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.

NumPy
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)
Drag options to blanks, or click blank then click option'
Bcos
C>
Dsin
Attempts:
3 left
💡 Hint
Common Mistakes
Adding ':' after angle in the key (should be empty).
Using 'sin' instead of 'cos' for cosine calculation.
Using '<' instead of '>' in the condition.