小编ben*_*456的帖子

防止在 Sympy 中计算乘法表达式

我正在生成一个带有两个分数的表达式,并希望使用 LaTeX 将整个表达式打印得漂亮,然后放在工作表上。

例如形式:

(5/7) * (3/4). 
Run Code Online (Sandbox Code Playgroud)

但是,当我执行以下操作时:

fract1 = sympy.sympify(Fraction(5,7))
fract2 = sympy.sympify(Fraction(3,4))
expression = sympy.Mul(fract1,fract2,evaluate=False)
Run Code Online (Sandbox Code Playgroud)

它返回

5*3/(7*4)
Run Code Online (Sandbox Code Playgroud)

显然,它正在组合分数,但并未实际评估,但我希望能够以适合作为数学工作表问题的格式生成它。

python latex numpy sympy python-3.x

5
推荐指数
1
解决办法
604
查看次数

避免使用嵌套的if语句

我目前有以下代码.我使用嵌套的if语句根据不同的情况返回不同的错误

if(!cipherFileRead.isEmpty() && !freqFileRead.isEmpty() ){

    if(freqChooser.getSelection()!=null){

        if(nearestFreq.isSelected()){
            file.writeToFile(decrypter.nearestFreq(cipherFileRead, freqFileRead), "output.txt");;
        }
        else if (rankingFreq.isSelected()){
            file.writeToFile(decrypter.byRanking(cipherFileRead, freqFileRead), "output.txt");;
        }

        returnMessage = "Succesfully decrypted to output.txt";
    }
    else{
        returnMessage = "Please select decryption type. Decryption unsuccesful";}
}
else{
    returnMessage = "Both files must be loaded and contain text. Decryption unsuccesful.";}

JOptionPane.showMessageDialog(null, returnMessage);
}  
Run Code Online (Sandbox Code Playgroud)

有没有更优雅的方法来实现这一点,没有大量可怕的IF语句?

java

2
推荐指数
2
解决办法
3201
查看次数

标签 统计

java ×1

latex ×1

numpy ×1

python ×1

python-3.x ×1

sympy ×1