Challenge - 5 Problems
Gamma Factorial Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of factorial for a positive integer
What is the output of this code snippet using scipy's factorial function?
SciPy
from scipy.special import factorial result = factorial(5, exact=True) print(result)
Attempts:
2 left
💡 Hint
Recall that factorial of 5 is 5*4*3*2*1.
✗ Incorrect
The factorial of 5 is 120 because 5*4*3*2*1 equals 120. Using exact=True returns an integer.
❓ data_output
intermediate2:00remaining
Gamma function values for half-integers
What is the output array from this code using scipy's gamma function for half-integers?
SciPy
import numpy as np from scipy.special import gamma x = np.array([0.5, 1.5, 2.5]) result = gamma(x) print(result)
Attempts:
2 left
💡 Hint
Gamma(0.5) equals sqrt(pi).
✗ Incorrect
Gamma(0.5) is sqrt(pi) ≈ 1.772, Gamma(1.5) = 0.5*sqrt(pi) ≈ 0.886, Gamma(2.5) = 1.5*0.5*sqrt(pi) ≈ 1.329.
❓ visualization
advanced3:00remaining
Plotting factorial vs gamma function
Which option produces the correct plot comparing factorial and gamma functions for integers 1 to 6?
SciPy
import matplotlib.pyplot as plt from scipy.special import factorial, gamma import numpy as np x = np.arange(1,7) plt.plot(x, factorial(x, exact=True), 'o-', label='factorial') plt.plot(x, gamma(x+1), 'x--', label='gamma(x+1)') plt.legend() plt.show()
Attempts:
2 left
💡 Hint
Recall gamma(n+1) = n! for positive integers n.
✗ Incorrect
Gamma function shifted by 1 matches factorial exactly for positive integers, so plots overlap.
🧠 Conceptual
advanced1:30remaining
Understanding gamma function domain
Which statement about the gamma function domain is correct?
Attempts:
2 left
💡 Hint
Think about poles of the gamma function.
✗ Incorrect
Gamma function has poles at zero and negative integers, so it is undefined there but defined elsewhere.
🔧 Debug
expert2:00remaining
Identify error in gamma function usage
What error does this code raise?
SciPy
from scipy.special import gamma result = gamma(-2) print(result)
Attempts:
2 left
💡 Hint
Gamma has poles at negative integers, check what scipy returns.
✗ Incorrect
Gamma at negative integers returns infinity (inf) in scipy, no exception is raised.