0
0
SciPydata~20 mins

Factorial and gamma functions in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gamma Factorial Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A120
B24
C720
DError
Attempts:
2 left
💡 Hint
Recall that factorial of 5 is 5*4*3*2*1.
data_output
intermediate
2: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)
A[0.88622693 1.32934039 3.32335097]
BTypeError
C[1.0 1.0 1.0]
D[1.77245385 0.88622693 1.32934039]
Attempts:
2 left
💡 Hint
Gamma(0.5) equals sqrt(pi).
visualization
advanced
3: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()
APlot shows two overlapping lines with factorial and gamma(x+1) values identical for integers 1 to 6.
BPlot shows factorial values increasing but gamma values constant at 1.
CPlot shows factorial values decreasing and gamma values increasing.
DPlot raises a TypeError due to incompatible types.
Attempts:
2 left
💡 Hint
Recall gamma(n+1) = n! for positive integers n.
🧠 Conceptual
advanced
1:30remaining
Understanding gamma function domain
Which statement about the gamma function domain is correct?
AGamma function is defined for all real numbers including zero.
BGamma function is defined for all real numbers except non-positive integers.
CGamma function is only defined for positive integers.
DGamma function is only defined for complex numbers with positive real part.
Attempts:
2 left
💡 Hint
Think about poles of the gamma function.
🔧 Debug
expert
2:00remaining
Identify error in gamma function usage
What error does this code raise?
SciPy
from scipy.special import gamma
result = gamma(-2)
print(result)
AValueError: math domain error
BZeroDivisionError
CNo error, prints inf
DOverflowError
Attempts:
2 left
💡 Hint
Gamma has poles at negative integers, check what scipy returns.