6/15 what is wrong?


#1

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


#2

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

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

#4

ERROR

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

print cubes_by_four

File "python", line 1
cubes_by_four = [c**3 in range(1,11) if (c**3)%4 == 0]
^
SyntaxError: invalid syntax

???


#5

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

#6

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

#7

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 ?


#8

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


#9

thanks @rydan ...it helps me..:grin:


#10

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