Challenge - 5 Problems
Trigonometry Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of numpy sine function on array
What is the output of this code snippet using numpy's sine function on an array of angles in radians?
NumPy
import numpy as np angles = np.array([0, np.pi/2, np.pi]) result = np.sin(angles) print(result)
Attempts:
2 left
💡 Hint
Recall sine values at 0, 90, and 180 degrees (in radians: 0, π/2, π).
✗ Incorrect
The sine of 0 is 0, sine of π/2 (90 degrees) is 1, and sine of π (180 degrees) is 0.
❓ data_output
intermediate1:30remaining
Number of elements in cosine output array
After running this code, how many elements does the resulting cosine array contain?
NumPy
import numpy as np angles = np.linspace(0, 2*np.pi, 50) cos_values = np.cos(angles) print(len(cos_values))
Attempts:
2 left
💡 Hint
np.linspace(start, stop, num) creates 'num' evenly spaced points.
✗ Incorrect
np.linspace with num=50 creates exactly 50 points, so the cosine array has 50 elements.
🔧 Debug
advanced2:00remaining
Identify the error in tangent calculation
What error will this code raise when calculating tangent values for these angles?
NumPy
import numpy as np angles = np.array([0, np.pi/2, np.pi]) tan_values = np.tan(angles) print(tan_values)
Attempts:
2 left
💡 Hint
Consider the tangent of π/2 (90 degrees).
✗ Incorrect
Tangent of π/2 is undefined (infinite), so numpy raises a RuntimeWarning for divide by zero.
🧠 Conceptual
advanced1:30remaining
Understanding output range of cosine function
Which of the following statements about the output range of numpy's cosine function is correct?
Attempts:
2 left
💡 Hint
Recall the range of the cosine function in trigonometry.
✗ Incorrect
Cosine values range from -1 to 1 for all real inputs.
🚀 Application
expert3:00remaining
Calculate and plot sine and cosine waves
Which option correctly calculates sine and cosine values for 100 points between 0 and 2π and plots both on the same graph?
Attempts:
2 left
💡 Hint
Check if both sine and cosine are plotted against the same x values and if labels are included.
✗ Incorrect
Option A correctly plots sine and cosine against x with labels and legend. Option A swaps axes, A plots tangent which can be problematic, D misses labels and legend.