Python Python Sequences Sequence Iteration Iterating over Ranges

Bummer: AssertionError: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] != 9 : Whoops, looks like my_list contains incorrect values or is

Little lost on appending the value

iterating_ranges.py
my_list = []
for my_list in range(10):
    print(my_list)
Daniel Adari
Daniel Adari
3,576 Points

As I understand from your question, you want to append the number from 0 to 9 (inclusive) to my_list.

my_list = []
for my_list in range(10):
    print(my_list)  # Here, you are printing the list before you appended any values.

My solution:

my_list = []  # Setting the list
for val in range(10):  # Iterating over the range. 
    my_list.append(val)  # Append 'val' to your list.

1 Answer

Steven Parker
Steven Parker
205,345 Points

The instructions gave you the code for adding to the list when they said "To append a value to a list, use the syntax my_list.append(val)." That example assumes that the list variable will be named "val", which would give you:

my_list = []
for val in range(10):
    my_list.append(val)

And you don't need to "print" anything for this challenge.