Now You Try!


#1

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

Here is my code:

cubes_by_four = [x**3 for x in range(1,10) if x % 3 == 0]

and it throws the error
Oops, try again. Looks like cubes_by_four is the wrong length. It should have 5 values.

And I don't understand how it's the wrong length. help plz?


#2

Check your range. It's supposed to include 10 (inclusive). Your range doesn't include 10. Also, I believe your conditional statement is a little off. Should be

if ( x ** 3 ) % 4 == 0 #If x**3 (cubes) are divisible by 4

#3

I tried that, and here is my new code:

cubes_by_four = [x**3 for x in range(1,11) if ( x ** 3 ) % 4 == 0]

but it throws the error: Oops, try again. It looks like nothing was printed to the console. ?


#4

cubes_by_four = [x**3 for x in range(1,11) if (x**3) % 4 == 0]
print cubes_by_four

Don't forget the print


#5

It doesn't look like you've included a print statement below the comprehension.


#6

AAhh thanks I knew I forgot something. :joy:


#7

this works but the description on the example said "The comprehension should consist of the cubes of the numbers 1 through 10"


#8

Use a list comprehension to create a list, cubes_by_four.
The comprehension should consist of the cubes of the numbers 1 through 10 only if the cube is evenly divisible by four.
Finally, print that list to the console.
Note that in this case, the cubed number should be evenly divisible by 4, not the original number.


#9

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