Hooray for Arrays | CyberStart Completion

Hooray for Arrays

Briefing:

If you thought functions were useful just wait until you learn about arrays! They’re simple things, just collections of data, but they’re really handy for programming. In this lesson you’ll learn how to create them, plus add and remove items in them, and more.

Hint:

Remember that we start counting arrays from 0.

So the fourth value in an array will be array[3]

0, 1, 2, 3. That’s four values but the highest number is 3

Code Solution:

The following code is the solution to this challenge. Please note that there may be alternative ways to complete this challenge.


# CHALLENGE 1: Create an array with the following values in it in
#             order:
#             42, 1337, "Coffee", "Anonymous" then print the array.
ch_1 = [42, 1337, "Coffee", "Anonymous"]
print(ch_1)

# CHALLENGE 2: Add two more values to the end of the array you created
#              in CHALLENGE 1: "Blue", "Sky" then print the array.
ch_1.append("Blue")
ch_1.append("Sky")
print(ch_1)

# CHALLENGE 3: Print the fourth value in the array you created in
#              CHALLENGE 1.
print(ch_1[3])

# CHALLENGE 4: Create a dict that includes the following values in
#              order: "Subject": "Hacking", "Grade": "A".
ch_4 = {"Subject": "Hacking", "Grade": "A"}

# CHALLENGE 5: Print the grade value in the dictionary you created in
#              CHALLENGE 4.
print(ch_4["Grade"])