如何删除 R/exams 中网状输出中的括号?

How to remove brackets in a reticulate output in R/exams?

我有以下单选练习RadicalPrimo.Rmd,目的是简化平方根:

```{r data generation, echo = FALSE, results = "hide"}
library("exams")
library("reticulate")

# use_python('/usr/bin/python3', required = TRUE)
use_python('/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/bin/python', required = TRUE)
options(scipen=999)
typ <- match_exams_device()
#--------------------------------------------------------
```

```{python, include=FALSE}
from sympy import *   
init_printing()     ##### Facilita la impresión en un formato legible
```

```{python, eval = TRUE, echo = FALSE,results='asis'}
import sympy
import random
nrand1 = random.randint(2, 200)
nram = nrand1*2
sol = sympy.sqrt(nrand1)
pp = print('$' + sympy.printing.latex(sol) + '$')
```

Question
========

Simplify: 

$$\sqrt{`r py$nrand1`}$$


Answerlist
----------

*   
```{python, eval = TRUE, echo = FALSE,results='asis'}
import sympy
print('$' + sympy.printing.latex(sol) + '$')
```

*   
```{python, eval = TRUE, echo = FALSE,results='asis'}
import sympy
import random 
nrand2 = random.randint(1, 200)
if (nrand2 != nrand1) & (nrand2<nrand1):
  inc2 = sympy.sqrt(nrand2)
  inc2b = sympy.root(nrand2,2)
  inc =random.sample((inc2,inc2b),1)
print('$' + sympy.printing.latex(inc) + '$')
```

*  
```{python, eval = TRUE, echo = FALSE,results='asis'}
import sympy
import random
nrand3 = random.randint(2, 200)
if (nrand2 != nrand1) & (nrand3 != nrand2) & (nrand3<nrand1):
  inc3 = sympy.sqrt(nrand3)
pp3 = print('$' + sympy.printing.latex(inc3) + '$')
```

*  
```{python, eval = TRUE, echo = FALSE,results='asis'}
import sympy
import random
nrand4 = random.randint(2, 200)
if (nrand2 != nrand1) & (nrand3 != nrand2) & (nrand4 != nrand3) & (nrand4<nrand1):
  inc4 = sympy.sqrt(nrand4)
pp4 = print('$' + sympy.printing.latex(inc4) + '$')
```

Solution
========

```{python, eval = TRUE, echo = FALSE,results='asis'}
import sympy
print('$' + sympy.printing.latex(sol) + '$')
``` 

Meta-information
================
exname:RadicalPrimo(single-choice)
extype:schoice
exsolution: 1000
exshuffle: TRUE

但是,选择列表中的某些答案带有不雅的方括号:

我已应用各种方法删除 Python 输出中的括号,但无济于事。我怎样才能永久删除这些括号?

在您的示例 inc 中,random.sample((inc2,inc2b),1) 的输出是 Python 中的 list。因此,打印时(在 Python 内或作为 LaTeX)添加括号:

>>> type(inc)
## <class 'list'>
>>> inc
## [sqrt(67)]
>>> sympy.printing.latex(inc)
## '\left[ \sqrt{67}\right]'

您可以简单地提取第一个元素并打印:

>>> inc = inc[0]
>>> type(inc)
## <class 'sympy.core.power.Pow'>
>>> inc
## sqrt(67)
>>> sympy.printing.latex(inc)
## '\sqrt{67}'