Ask Question
7 November, 00:31

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.

+4
Answers (1)
  1. 7 November, 00:42
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers