Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So I have this program:

#first is the first number, c is the constant it increments by, and l is the last number
Python
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?
Posted
Updated 9-Dec-14 4:17am
v5
Comments
Sergey Alexandrovich Kryukov 9-Dec-14 10:34am    
What makes you thinking anything is wrong?
—SA
Nick Salesky 9-Dec-14 10:53am    
that it doesn't return the complete range when tested. Even the normal range() method doesn't return the whole range

1 solution

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 using while 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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900