python - 是否可以使用 python 解决演绎推理测试问题?

标签 python equation simultaneous

给定一个演绎推理风格的口头问题,是否可以用Python解决?

如果潜在变量从未被分配真实世界/实体值而不是彼此之间的距离,可以做到吗?这意味着没有固定的起点(即 x = 1)。

我尝试将所有变量分配为 0 以开始,然后从那里开始构建,但我认为这是不对的。

我在这里有一个示例问题可以尝试,并且我已经包含了我想象的代码的样子。我知道它不是以完美的 PEP8 风格编写的,所以请不要批评...这更多的是我如何尝试解决问题的一个可能的例子。

"""Denise arrived at the party 1 hour later than Kylie and 30 minutes before James.
Melissa arrived at the party 30 minutes earlier than Denise and 45 minutes earlier than Sarah.

Is the statement below True?

When James arrived, he found both Melissa and Denise enjoying the party and learned that Sarah
arrived at the party 30 minutes prior to him."""

def deductive_reasoning():
    kylie = 0
    james = 0
    denise = 0
    sarah = 0

    melissa = [denise - 30, sarah - 45]
    denise = [kylie + 60, james - 30]
    if (james > melissa[0] and melissa[1]) and (james > denise[0] and denise[1]) and (sarah == james - 30):
        print("That is true")
    else:
        print("That is not true")

deductive_reasoning() 

最佳答案

def deductive_reasoning():
    # "Denise arrived at the party 1 hour later than Kylie"
    # Some time point needs to be pinned, so we'll arbitrarily pin Kylie
    kylie = 0

    # and set Denise relative to Kylie
    denise = 60

    # "and 30 minutes before James"
    james = denise + 30

    # "Melissa arrived as the party 30 minutes earlier that Danise"
    melissa = denise - 30

    # "and 45 minutes earlier than Sarah"
    sarah = melissa + 45
    
    # Query: Did James arrive at a time after both Melissa and Denise
    #        and 30 minutes after Sarah?
    return james > melissa and james > denise and james - sarah == 30

可以编写一个函数来编码特定的逻辑难题。但究竟是软件解决了这个难题,还是程序员在将难题转化为代码的过程中解决了这个难题呢?就我个人而言,我会说是程序员。

关于python - 是否可以使用 python 解决演绎推理测试问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73382713/

相关文章:

latex - latex :如何在$$内换行

python - 有没有办法在脚本出现错误后自动运行

Python:Peewee 更新查询不起作用

c - 使用 else if 的 printf 方程

安卓 4.3 : How to connect to multiple Bluetooth Low Energy devices?

python - 如何在 python 中同时运行两个 turtle ?

MATLAB 同时在单独的子图中绘制移动数据点

python - 如何每行进行一对组合

python - 使用 Google App Engine 标准环境时将 "/blog"转发到 WordPress 安装

c# - 寻找 .NET 数学方程式编辑器和求解器控件