Код: Выделить всё
import random
# Generate random values of k and m between 1 and 5
k = random.randint(1, 5)
m = random.randint(1, 5)
# Calculate necessary variables
m_k = m - k
m_1 = m - 1
m_plus = m + 1
k_1 = k - 1
k_plus = k + 1
# Create with the correct answer marked
answers = [
f"\\checkmark \\; \\frac{{(n+{m}) !}}{{{k} ! (n+{m_k}) !}}", # Correct answer
f"\\frac{{(n+{m_1}) !}}{{{k_1} ! (n+{m_k}) !}}", # Wrong answer
f"\\frac{{(n+{m_plus}) !}}{{{k_plus} ! (n+{m_k}) !}}", # Wrong answer
f"\\frac{{(n+{m}) !}}{{{k_plus} ! (n+{m_k}) !}}" # Wrong answer
]
# Mix the answers
random.shuffle(answers)
# Generate text in LaTeX format
latex_output = f"""
After simplifying the expression
$$\\frac{{(n+{m_1}) !}}{{{k} ! (n+{m-k-1}) !}} + \\frac{{(n+{m_1}) !}}{{{k-1}! (n+{m-k})!}}$$
indicate which of the following results is correct:
\\[
\\square \\; {answers[0]} \\quad\\quad \\square \\; {answers[1]} \\quad\\quad \\square \\; {answers[2]} \\quad\\quad \\square \\; {answers[3]}
\\]
"""
print(latex_output)
Дело в том, что иногда я получаю такие результаты:
Код: Выделить всё
After simplifying the expression
$$\frac{(n+0) !}{1 ! (n+-1) !} + \frac{(n+0) !}{0! (n+0)!}$$
indicate which of the following results is correct:
\[
\square \; \frac{(n+2) !}{2 ! (n+0) !} \quad\quad \square \; \checkmark \; \frac{(n+1) !}{1 ! (n+0) !} \quad\quad \square \; \frac{(n+1) !}{2 ! (n+0) !} \quad\quad \square \; \frac{(n+0) !}{0 ! (n+0) !}
\]
Подробнее здесь: https://stackoverflow.com/questions/791 ... latex-code
Мобильная версия