问题描述
我正在用python编写一个小应用程序,它可以让用户回答数学问题.我遇到的问题是检查他们的答案.
I'm writing a small app in python which lets users answer math questions. The problem I'm having is checking their answers.
说有一个问题,例如:因素x^2 + 3x +2
"
Say there's a question like: "Factorise x^2 + 3x +2
"
有不同的回答方法;例如:
There are different ways to answer this; for example:
- (x +1)(x + 2)
- (x + 2)(x +1)
- (2 + x)(x + 1)
- 等
有没有一个图书馆可以检查答案是否等同于另一个?特别是不能简化给定答案的一种.所以:
Is there a library which will check if an answer is equivalent to another? Particularly one which doesn't simplify the given answer; so:
(x + 1)(x + 2)
=== (2 + x)(x + 1)
但是
(x + 1)(x + 2)
!== x^2 + 3x +2
我考虑过要使用wolframalpha,这有可能吗?如果可以,应该使用什么语法?
I thought about using wolframalpha for this — would this be possible — and if so what syntax should I use?
谢谢!
推荐答案
您可以尝试使用符号数学库,例如象征.
You could try using a symbolic math library like sympy.
在答案和答案上均调用简化逻辑.由用户提供的一种.在两个逻辑上都运行逻辑解决了文档中提到的此问题:
Call the simplify logic on both your answer and the one supplied by the user. Running the logic on both addresses this issue noted in the documentation:
这篇关于检查两个数学答案是否相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!