Now you try. Wrong length .... why?


#1



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


Can anyone see bug in this bit of code ? Seems to be quite simple.


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


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

print cubes_by_four


#2

Hi, @markiscoding ,

The cube of x is x ** 3, not x ** 4.

Also, change your test. You have ...

if x % 4 == 0

Test, instead, whether the cube of x mod 4 is equivalent to 0. The instructions have ...

... if the cube is evenly divisible by four (my emphasis added)


#3

This is what I've got:

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

print cubes_by_four

Am I getting closer ?


#4

Got it ....

had to fix line from ==1 to ==0


#5

Thank you .... appreciate your help mate !


#6

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