13,420
edits
Changes
→PART 3 - Iterating Over Lists
square(value)
</source>You should see the effectiveness of from the previous demonstrationthe advantage of using lists with functions. Although useful, the demonstration above only prints the squares as opposed to saving them for future use. The next demonstration uses a function that loops through lists, squares the values, but saves the squares in a new list.<br><br>
:#Issue the following:<source>
list_of_numbers = [ 1, 5, 2, 6, 8, 5, 10, 2 ]
</source>
:::*The list '''my_list''' should have the values: '''1, 2, 3, 4, 5'''
:::*The script should have a function called add_item_to_list(my_list)