Now You Try!


#1

The comprehension should consist of the cubes of the numbers 1 through 10 only if the cube is evenly divisible by four.
What's wrong in this code :
cubes_by_four=[x**3 for x in range(1,11) if (x**3/4)%2==0]
print cubes_by_four

[1, 8, 27, 64, 216, 512, 729, 1000]
error:
Oops, try again. Looks like cubes_by_four is the wrong length. It should have 5 values.


#2

Figured out in if condition:
it should be :-
if (x**3)%4==0


#3

Every thing is fine other than the Instruction they said 1 through 10 only but u used the range 1 to 11.
cubes_by_four = [i**3 for i in range(1,11) if (i**3 ) % 4 == 0]


#4

I got this error "
It looks like your list has the wrong value at index 0. It should be 8."
this is my line:
cubes_by_four = [ x for x in range(1, 11) if (x**3) % 4 == 0]

what's wrong?


#5

@lubrito: The problem with your code is that you're assigning values whose triple of it divided by four has a remainder zero but you're not changing them!
You're simply putting the original value inside of your list, so instead of the value 8, it will be stored the value 2;

Try doing

x**3

other than

x

Hope it helps!

Edit: that change should be before you use the for loop.


#6

@g4be thankyou! I was missing exactly that.