Stride Length. to_one_hundred problem


#1



https://www.codecademy.com/courses/python-beginner-en-KAgt5/2/4?curriculum_id=4f89dab3d788890003000096#


Hello! I had a little problem while doing exercise 10 in advansed topics. At the beginning of the exercise you have see code like that in editor:

to_one_hundred = range(101)
# Add your code below!

The task sounds like "Create a variable, backwards_by_tens, and set it equal to the result of going backwards through to_one_hundred by tens. Go ahead and print backwards_by_tens to the console."
So, I've wrote this code:

to_one_hundred = range(101)
# Add your code below!
backwards_by_tens = to_one_hundred[:9:-1]
print backwards_by_tens

And I've got a warning "Oops, try again. to_one_hundred should include 0, but does not. ". I tried to add 0 by my own, but it didn't change the situation at all. What am I doing wrong? Thank you.


#2

I'm not sure where you're getting your 9 and -1 from, you'll need to reconsider those. Also make sure to look at what you print and compare to what's asked for and what your code is. If you're unsure what the slicing parameters do you can always just change them and see what effect that has on your print.


#3

to_one_hundred = range(101)
# Add your code below!
backwards_by_tens = to_one_hundred[::-10]
print backwards_by_tens

That's what I did.
What I don't get is why you put [:9:-1]. you should put [::-10]


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.