I knew the formula but fumbled the two-sided case for a second.
Start by clarifying the function signature and edge cases, then implement using scipy.stats for reliability. Explain the logic for one-sided vs two-sided p-values and how the distribution choice affects the calculation.
Pro tip: Mention that in practice, you'd use scipy.stats rather than implementing the CDF yourself, but be prepared to explain the underlying math (e.g., using the survival function for numerical stability).
Confirm input types, handle invalid inputs (e.g., negative degrees of freedom), and discuss one-sided vs two-sided definitions.
Use scipy.stats.norm for Z and scipy.stats.t for t-distribution, leveraging their CDF methods.
For one-sided, use the CDF or survival function depending on the direction; for two-sided, double the one-sided p-value or use the absolute statistic.
Write a Python function that takes test_statistic, distribution, df, and alternative, and returns the p-value.
Run unit tests with known values (e.g., z=1.96, two-sided p≈0.05) to ensure correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.