generate number start, stop, step to number inclusive. returning false?!
i was on the site pyschools working through the exercises, but i dont understand why it wont accept the code i input.
http://www.pyschools.com/quiz/view_question/s4-q2
Create a function generateNumbers(start, end, step) that takes in three numbers as arguments and returns a list of numbers ranging from start to the end number (inclusive)and skipping numbers based on the step specified in the arguments. Note: The function range(x, y, z) can takes in 3 arguments. For example, range(1, 11, 2) will return a list of numbers [1,3,5,7,9].
Examples
>>> generateNumber(2, 10, 2)
[2, 4, 6, 8, 10]
>>> generateNumber(10, 10, 1)
[10]
>>> generateNumber(20, 0, -3)
[20, 17, 14, 11, 8, 5, 2]
so i used the code;
def generateNumber(start, end, step):
return [i for i in range(start, end+1, step)]
but it says its not right, whats wrong with it?
pwolf
Junior Poster in Training
71 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
but it says its not right, whats wrong with it?
The code works,python always give you Traceback.
Post Traceback next time.
Run of code.
>>> generateNumber(0,10,2)
[0, 2, 4, 6, 8, 10]
>>> generateNumber(20,0,-3)
[20, 17, 14, 11, 8, 5, 2]
>>>
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
The code works,python always give you Traceback.
Post Traceback next time.
Run of code.
>>> generateNumber(0,10,2)
[0, 2, 4, 6, 8, 10]
>>> generateNumber(20,0,-3)
[20, 17, 14, 11, 8, 5, 2]
>>>
sorry, i know it works, but for the exercise in the link and the result of my solution isnt passing, i dont know why.
pwolf
Junior Poster in Training
71 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
You got to let us know why it isn't passing?
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
The question itself is not clear from start to the end number (inclusive)but the results do not include the end number range(1, 11, 2) will return a list of numbers [1,3,5,7,9].
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
if i knew why it wasn't passing, i wouldn't be stuck.
pwolf
Junior Poster in Training
71 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0