6/15 what is wrong?

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

this line

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

should be

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


cubes_by_four = [c3 in range(1,11) if (c3)%4 == 0]

print cubes_by_four

File “python”, line 1
cubes_by_four = [c3 in range(1,11) if (c3)%4 == 0]
SyntaxError: invalid syntax


Your code should rather be this

cubes_by_four = [c**3 for c in range(1,11) if (c**3)%4 == 0]
#                     ^<->^
#                     missing that
#                     for statement
#                     with c as the iterator

I did the way I use to work out the cube numbers back in school. it worked though:

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

print cubes_by_four

I just curious… the instruction said 1 through 10 only, but here we wrote like this range(1,11) rather than range(1,10) …any one can explain ?

@textrunner60544 take a look at this post it explains the range function
Click here to post

1 Like

thanks @rydan …it helps me…:grin:

Python counts like this:
range(starting-number, number-it-doesn’t-count)