Ask Question
1 February, 18:34

g Create an array of five animals. Use a for loop to display the values stored in that array. Add two more animals to the end of that array. Sort the array and display the sorted array on the screen.

+3
Answers (1)
  1. 1 February, 20:27
    0
    animals = ["Dog", "Lion", "Goat", "Zebra", "Cat"]

    for animal in animals:

    print (animal)

    x = animals. insert (5, "Lizard")

    y = animals. insert (6, "Bat")

    z = sorted (animals)

    print (z)

    Explanation:

    The question can be solved using various back-end coding language like python, java, jа vascript etc. But I will be writing the code with python.

    The first question said we should create an array or list of five animals.

    animals = ["Dog", "Lion", "Goat", "Zebra", "Cat"] → I created the five animals in a list and stored them in the variable animals.

    for animal in animals: I used a for loop to iterate through the list print (animal) I used print statement to display the values stored in the array or list.

    x = animals. insert (5, "Lizard") I added an animal, lizard to the end of the array

    y = animals. insert (6, "Bat") I added another animal, Bat to the end of the array.

    z = sorted (animals) I sorted the array according to alphabetical number.

    print (z) I displayed the sorted array.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “g Create an array of five animals. Use a for loop to display the values stored in that array. Add two more animals to the end of that ...” in 📙 Engineering if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers