【发布时间】:2017-11-04 17:57:06
【问题描述】:
x = [1, 3, 2, 5, 7]
从列表的第一个值开始:
如果下一个值更大,则打印"\nthe value x is greater than y"
如果下一个值相等,则打印"\nthe value x is equal to y"
如果下一个值更小,则打印"\nthe value x is smaller than y"
如何将其翻译成准确的 Python 代码?我实际上正在使用 pandas 数据框,我只是通过使用列表作为示例对其进行了简化。
x = [1, 3, 2, 5, 7]
有了上面给出的,输出应该是这样的:
the value 3 is greater than 1
the value 2 is smaller than 3
the value 5 is greater than 2
the value 7 is greater than 5
【问题讨论】:
-
如果值相等怎么办?如果列表中的值少于两个怎么办?你试过什么代码,你卡在哪里了?示例输出中的最后一行不应该是
the value 7 is greater than 5吗? -
我已经编辑了错别字,很抱歉。我对所有事情都束手无策,我试着自己思考并做,但我什至不知道从哪里开始。