Manipulating Python Script Variables and Lists

In this activity, you will get more practice declaring and manipulating variables and lists.

Starter file

# Create a list, `list_1`,  with `0`, `1`, `2`, `3` as values.


# Create a list, `list_2` with `4`, `5`, `6`, `7` as values.


# Create a list, `list_3` with `8`, `9`, `10`, `11` as values.


# Create a list, `list_4` with `12`, `13`, `14`, `15` as values.


# Print the 3rd index of `list_1`.


# Print the 1st index of `list_2`.


# Print the 2nd index of `list_3`.


# Print the 4th index of `list_4`.

Instructions

Open the starter file and perform the following:

  1. Create a list, list_1, with 0, 1, 2, 3 as values.
  2. Create a list, list_2 with 4, 5, 6, 7 as values.
  3. Create a list, list_3 with 8, 9, 10, 11 as values.
  4. Create a list, list_4 with 12, 13, 14, 15 as values.
  5. Print the 3rd index of list_1.
  6. Print the 1st index of list_2.
  7. Print the 2nd index of list_3.
  8. Print the 4th index of list_4.

Solution

# Create a list, `list_1`,  with `0`, `1`, `2`, `3` as values.
list_1 = [0, 1, 2, 3]

# Create a list, `list_2` with `4`, `5`, `6`, `7` as values.
list_2 = [4, 5, 6, 7]

# Create a list, `list_3` with `8`, `9`, `10`, `11` as values.
list_3 = [8, 9, 10, 11]

# Create a list, `list_4` with `12`, `13`, `14`, `15` as values.
list_4 = [12, 13, 14, 15]

# Print the 3rd index of `list_1`.
print(list_1[2])

# Print the 1st index of `list_2`.
print(list_2[0])

# Print the 2nd index of `list_3`.
print(list_3[1])

# Print the 4th index of `list_4`.
print(list_4[3])

We will be happy to hear your thoughts

Leave a reply