Good job! In this lesson, you learned
- how to write a for loop
- how to use
rangein a loop
- what infinite loops are and how to avoid them
- how to skip values in a loop
- how to write a while loop
- how to make lists with one line
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
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.