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

out put:

```
[4, 16, 36, 64, 100]
```

i get this:

```
Oops, try again. It looks like your list has the wrong value at index 0. It should be 8.
```

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

out put:

```
[4, 16, 36, 64, 100]
```

i get this:

```
Oops, try again. It looks like your list has the wrong value at index 0. It should be 8.
```

2 Likes

Hi here

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

You want the cube of x so it should be like that `(x**3)`

instead of `x*x`

do the same in the `if statement`

8 Likes

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

Thank you

6 Likes

Even if the above worked shouldn’t it be:

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

2 Likes

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

3 Likes

your are right! thank you!

1 Like

How come is this line justified? " if the cube is evenly divisible by four". I don’t see this check. Is there something I’m missing?

Shouldn’t it be something like this:

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

Here’s what I came up.

(This was tricky)

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

1 Like

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

print cubes_of_four

output: [8, 64, 216, 512, 1000]

None

error message: Oops, try again.

You got the following error: global name ‘cubes_by_four’ is not defined. Did you create a list called cubes_by_four?

can somebody guide me as to where I am going wrong?

Hi your list of **comprehension** should be **cubes_by_four** instead of **cubes_of_four**

3 Likes

Yes, I realized that after I posted the question. Thanks anyways

cubes_by_four = [x

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

print cubes_by_four

Hi, what is the == 0 for at the end?

Hi @xiaokiraa.

The ==0 at the end is used to check whether the mod 4 of the number gives remainder 0. Basically the mod function is used to divide a number and return the remainder after division.

So in the above code the cube of the number is divided by 4 and is checked whether the number after cubing is divisible by 4 using the ==0

Hope this helps

1 Like

why should it be x ** 3?

1 Like

Try this

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

1 Like

Try this one

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

print cubes_by_four

I was just trying to figure that out too. I think it’s because the problem wants you to print `x**3`

, so the `x**3`

at the start prints the cubed value and the x**3 in the if statement filters out the cubed numbers that are divisive by 4

1 Like

The instructions specify this …

The comprehension should consist of the cubes of the numbers 1 through 10 only if the cube is evenly divisible by four.

Based on that, it is the cube of each number that should be tested. Accordingly, the author of the course intended for the user to write this as the condition in the list comprehension …

```
n ** 3 % 4 == 0
```

There are various ways to accomplish the required outcome. Other conditions will also pass, provided that the result is that `cubes_by_four`

includes all of the appropriate numbers, and only those numbers.

3 Likes