Untitled

mail@pastecode.io avatar
unknown
python
a month ago
779 B
0
Indexable
Never
# 2D Arrays Demo
# DKe
# 22/03/24

# 2D Arrays allow us to model data as if it is in a table

zoo_animals = [["Meerkat", 22], 
               ["Gorilla", 6], 
               ["Lion", 2],
               ["Penguin", 12]]

# What will this print instruction output?
print (f"There are currently {zoo_animals[0][1]} {zoo_animals[0][0]}s in the zoo.")

# Print how many lions are currently in the zoo
print (f"There are currently {zoo_animals[2][1]} {zoo_animals[2][0]}s in the zoo.")

# Update the array to add that there are 12 penguins in the zoo and print this information 
print (f"There are currently {zoo_animals[3][1]} {zoo_animals[3][0]}s in the zoo.")

# Loop through the 2D array to print all of the animals currently in the zoo
for animal in zoo_animals:
    print(animal)
Leave a Comment