Help with 11 practice makes perfect i dont understand


#1

help me please. ineed a valubal answer


#2

is thid correct

to_21 = range(1,22)

odds = to_21[::2]

middle_third = to_21[7:14]

print to_21
print odds
print middle_third


#3

and bye coz i need to go to sleep its midnight


#4

to_21 = range(1,22) doesn’t create a list with the numbers 1 to 21 to do that you could use list(range(1,22)) or to_21 = [x for x in range(1,22)]. The rest is fine.


#5

In Python 2 it does. This site uses Python 2.7.x.

is Python 3.x.

List comprehensions are not covered until the Advanced Topics unit.


#6

You’re right @mtf. I forgot they’re using Python 2. Mainly because I searched for the exercise in question and could not find it because I couldn’t remember how it was done in the exercise. I know it’s there somewhere. But anyway thanks for reminding me. @digitalninja71913 it’s right.


#7

As it turns out, this IS from the advanced topics module.

https://www.codecademy.com/en/courses/learn-python/lessons/advanced-topics-in-python/exercises/practice-makes-perfect-1


#8

Well spotted @mtf. Although it wouldn’t have helped me, I used a list comprehension.


#9

The beauty of programming with a language such as Python (or JS or Ruby, etc.) is that there are multiple ways to accomplish the same end. Some may be more elegant, some more efficient.

For the above problem, range and list slicing is all that’s needed. The OP is using the simplest method.


#10

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