List Review Exercises
From WLCS
Objective:
- To review basic list concepts:
- accessing lists
- changing list elements
- list traversal
Resources:
Directions:
- Save all of your responses in a text file named listReview.txt or listReview.py
- Complete #1-12 without using a computer (closed-book, closed-computer)
- Complete #13-15 with a computer
Exercises: Assume that you have the following list: nums = [3, 2, 6, 57, 8, 9, 33, 0, 45]
- What is the value of the first element in the list?
- What is the value of the last element in the list?
- What is the length of the list? len(nums) = ???
- What is the value of nums[5]
- What is the value of nums[2]
- What is the index (location) of the 33 in the list?
- What is the index (location) of the 6 in the list?
- nums[3] + nums[6] = ???
- nums[0] + nums[8] = ???
- What does len(nums) - 2 = ???
- What is the value of the element: nums[ len(nums) - 2 ]
- What does nums[2] = nums[5] do? What does the list look like after that?
- Write a loop that traverses and prints out all the elements in nums
- Write a loop that traverses and prints out every other element in nums
- Write a loop that traverses nums backwards and prints out the list in reverse