范围复制未达到完整范围 [英] Range copy not getting complete range
本文介绍了范围复制未达到完整范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有这个程序:
#first是第一个数字,c是增量的常数,l是最后一个数字
def seqlist(first,c,l):
L = []
while first< l:
L.append(第一个)
优先+ = c
继续
返回 L
(以上代码在实际程序中缩进)
但它没有返回完整的范围。我试过使用实际的范围函数,但它返回相同的东西。我做错了什么?
解决方案
它确实返回了正确的范围,正如您定义的那样。我甚至在Python解释器上进行了检查,以防万一;一切正常。 这不是你的代码错了;从你的话来看,听起来你的期望是错误的。
注意两件事:1)你正在使用而循环,这意味着检查在每次迭代之前完成,而不是在之后;该含义对应于该词的常识英语含义; 2)你使用运算符'<',而不是'< =';因此,如果您希望在某些情况下
l
在范围内,则不会发生。
< DD> -SA
So I have this program:
#first is the first number, c is the constant it increments by, and l is the last number
def seqlist(first,c,l):
L = []
while first < l:
L.append(first)
first+=c
continue
return L
(The above code is indented in the actual program)
But it doesn't return the complete range. I have tried using the actual range function, but it returns the same thing. What am I doing wrong?
解决方案
It does return correct range, exactly as you defined it. I even checked it up on Python interpreter, just in case; all works correctly. This is not that your code is wrong; from your words, it sounds like your expectations are wrong.
Note two things: 1) you are usingwhile
loop, which means that the check is done before each iteration, not after; the meaning corresponds to the common-sense English meaning of this word; 2) you use the operator '<', not '<='; so, if you expect, in some cases,l
to be in range, it cannot happen.
—SA
这篇关于范围复制未达到完整范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文