给出一个演绎推理风格的口头问题,有可能用Python语言解决吗?

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

我试着从一开始就给所有变量赋值0,然后从那里开始构建,但我认为这是不正确的.

我在这里有一个示例问题要try ,我已经包括了我想象的代码看起来是什么样子.我知道它不是用完美的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相关问答推荐

如何在BeautifulSoup/CSS Select 器中处理regex?

跳过嵌套JSON中的级别并转换为Pandas Rame

如何找出Pandas 图中的连续空值(NaN)?

使用Python异步地持久跟踪用户输入

裁剪数字.nd数组引发-ValueError:无法将空图像写入JPEG

在第一次调用时使用不同行为的re. sub的最佳方式

使用np.fft.fft2和cv2.dft重现相位谱.为什么结果并不相似呢?

如何在Django模板中显示串行化器错误

迭代工具组合不会输出大于3的序列

Parsel无法访问嵌套元素

Raspberry Pi Pico W、WebSockets和从中获取数据

如何将数据从一个数据框按行添加到另一个数据框,仅当两个数据框中第一列的值相等时?

如何在Ubuntu上更新ChromeDriver二进制文件

从来自另一个Python脚本的消息中获取FlaskServer中的错误字段

如何动态修改气流任务decorator 属性?

我很难用Python Pandas打开旧格式的XLS文件

使用boto3检索AWS机密

删除GeoAxes子图中的顶部和右侧脊椎

在Python中优化乘法FOR循环

Shopware 6 REST-API产品更新不起作用