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]

  1. What is the value of the first element in the list?
  2. What is the value of the last element in the list?
  3. What is the length of the list? len(nums) = ???
  4. What is the value of nums[5]
  5. What is the value of nums[2]
  6. What is the index (location) of the 33 in the list?
  7. What is the index (location) of the 6 in the list?
  8. nums[3] + nums[6] = ???
  9. nums[0] + nums[8] = ???
  10. What does len(nums) - 2 = ???
  11. What is the value of the element: nums[ len(nums) - 2 ]
  12. What does nums[2] = nums[5] do? What does the list look like after that?
  13. Write a loop that traverses and prints out all the elements in nums
  14. Write a loop that traverses and prints out every other element in nums
  15. Write a loop that traverses nums backwards and prints out the list in reverse