random.randint(a, b) includes b, where b=4000 would cause exception (#425)

* random.randint(a, b) includes b, where b=4000 would cause exception

* math.factorial only works with integers starting python 3.9

* A constant equation does not have a stationary point
This commit is contained in:
Xinyu Zhou
2025-06-24 08:59:35 +08:00
committed by GitHub
parent 7ea9bd4a8a
commit 82ff506c98
2 changed files with 11 additions and 2 deletions

View File

@@ -82,7 +82,12 @@ def stationary_points(max_exp=3, max_coef=10):
| $f(x)=6x^3 + 6x^2 + x + 8$ | ${- \frac{1}{3} - \frac{\sqrt{2}}{6}, - \frac{1}{3} + \frac{\sqrt{2}}{6}}$ | | $f(x)=6x^3 + 6x^2 + x + 8$ | ${- \frac{1}{3} - \frac{\sqrt{2}}{6}, - \frac{1}{3} + \frac{\sqrt{2}}{6}}$ |
""" """
solution = '' solution = ''
while len(solution) == 0:
# A constant function has no stationary points, and the answer will be Reals. e.g.:
# x = sympy.symbols('x')
# s = sympy.stationary_points(1 + 0 * x , x)
# assert s == sympy.Reals
while solution == sympy.Reals or len(solution) == 0:
x = sympy.symbols('x') x = sympy.symbols('x')
problem = 0 problem = 0
for exp in range(max_exp + 1): for exp in range(max_exp + 1):

View File

@@ -97,6 +97,9 @@ def base_conversion(max_num=60000, max_base=16):
def _newton_symbol(n, k): def _newton_symbol(n, k):
"""Utility of binomial_distribution()""" """Utility of binomial_distribution()"""
# math.factorial only works with integers starting python 3.9
# ref: https://docs.python.org/3/library/math.html#math.factorial
n, k = int(n), int(k)
return math.factorial(n) / (math.factorial(k) * math.factorial(n - k)) return math.factorial(n) / (math.factorial(k) * math.factorial(n - k))
@@ -190,13 +193,14 @@ def complex_to_polar(min_real_imaginary_num=-20, max_real_imaginary_num=20):
return problem, f'${theta}$' return problem, f'${theta}$'
def decimal_to_roman_numerals(max_decimal=4000): def decimal_to_roman_numerals(max_decimal=3999):
"""Decimal to Roman Numerals """Decimal to Roman Numerals
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |
| --- | --- | | --- | --- |
| The number $92$ in roman numerals is: | $XCII$ | | The number $92$ in roman numerals is: | $XCII$ |
""" """
assert 0 <= max_decimal <= 3999, f"max_decimal({max_decimal}) must be <= 3999"
x = random.randint(0, max_decimal) x = random.randint(0, max_decimal)
x_copy = x x_copy = x
roman_dict = { roman_dict = {