Good job! In this lesson, you learned

  • How to write a for loop.
  • How to use range in a loop.
  • How to write a while loop.
  • What infinite loops are and how to avoid them.
  • How to control loops using break and continue.
  • How to write elegant loops as list comprehensions.

Let’s get some more practice with these concepts!



Create a list called single_digits that consists of the numbers 0-9 (inclusive).


Create a for loop that goes through single_digits and prints out each one.


Before the loop, create a list called squares. Assign it to be an empty list to begin with.


Inside the loop that iterates through single_digits, append the squared value of each element of single_digits to the list squares. You can do this before or after printing the element.


After the for loop, print out squares.


Create the list cubes using a list comprehension on the single_digits list. Each element of cubes should be an element of single_digits taken to the third power.


Print cubes.

Good job!

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?