python-将文本解析为代数表达式
我必须将下面的问题陈述转化为代数方程: 10年前父亲的年龄是儿子的三倍。十年后,父亲的年龄将是儿子的两倍python-将文本解析为代数表达式,python,Python,我必须将下面的问题陈述转化为代数方程: 10年前父亲的年龄是儿子的三倍。十年后,父亲的年龄将是儿子的两倍 任何建议让爸爸的名字叫鲍勃,儿子叫克里斯托弗。我认为最适合您的解决方案是Wolfram | Alpha alonside,它具有非常简单的Python API: 这当然需要 下面这行假设你有自己的 现在我们可以用苹果的语言来定义我们的问题。我们假设Bobby比Bob小10岁,Chris和Christopher也一样 >>> problem = '''Bobby has 3
任何建议让爸爸的名字叫鲍勃,儿子叫克里斯托弗。我认为最适合您的解决方案是Wolfram | Alpha alonside,它具有非常简单的Python API: 这当然需要 下面这行假设你有自己的 现在我们可以用苹果的语言来定义我们的问题。我们假设Bobby比Bob小10岁,Chris和Christopher也一样
>>> problem = '''Bobby has 3 times the number of apples as Chris has.
Bob has 10 more apples than Bobby has.
Christopher has 10 more apples than Chris has.
Bob has 2 times the number of apples as Christopher has.'''
结果以秒为单位提供:
>>> res = client.query(problem)
>>> for pod in res.pods:
... if pod.title == 'Results':
... print pod.text
...
Bob has 40 apples.
以下是方程式:
>>> for pod in res.pods:
... if pod.title == 'Equations with variables':
... for i in pod:
... print i.text
...
bobb = 3 × chris
bob = bobb+10
christ = chris+10
bob = 2 × christ
其中,bobb
表示Bob 10年前的年龄(Bobby),chris
表示Christopher 10年前的年龄(Christopher),Bob
表示Bob,Christopher
表示Christopher 10年后的年龄
祝你好运,玩得开心 这与python无关。。。如果你解不出四年级的数学题,我就担心你。10年前父亲和儿子的年龄分别是3岁和x岁。然后,(3x+10)+10=2[(x+10)+10]3x+20=2x+40x=20。不过,Python在这里的位置是什么?使用Python(x-10)=3y转换它,我投票决定关闭它
>>> res = client.query(problem)
>>> for pod in res.pods:
... if pod.title == 'Results':
... print pod.text
...
Bob has 40 apples.
>>> for pod in res.pods:
... if pod.title == 'Equations with variables':
... for i in pod:
... print i.text
...
bobb = 3 × chris
bob = bobb+10
christ = chris+10
bob = 2 × christ