Time: 10-15 minutes
Purpose: Give you practice with using for loops in python.
Introduction: Try to work out the following tasks in python and run them to make sure they do what you expect.
Tasks:
- Use a loop to make list2 have values that are one more than the values in list1 (i.e. list2 should be [2,3,4])
list1 = [1,2,3]
list2 = []
- use a loop to print out the numbers 1-5 multiplied by themselves (i.e. it should print out 1, 4, 9, 16, and 25)
- use list1 and list2 above and put the values of adding each of the items in those list together into a third list (i.e. list3 should be [3,5,7] since 1+2=3, 2+3=5 and 3+4=7) - use a loop and the zip function.
list3 = []
Further learning resources:
- https://data36.com/python-for-loops-explained-data-science-basics-5/
- https://realpython.com/python-for-loop/
A file showing a possible solution is available on github here