Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab Assignment Prompt: Count Zoo Animals You work at a zoo, and the director of the zoo wants your help keeping track of the numbers

Lab Assignment Prompt: Count Zoo Animals You work at a zoo, and the director of the zoo wants your help keeping track of the numbers of animals in the zoo, to accurately purchase the right amount of food for each kind of animal.

1. Create a function that accepts a list as its input parameter and returns a dictionary

Create a function that accepts a list of animals as its input parameter, and returns a dictionary with counts of each kind of animal from the provided list.

Requirements: Given a list of animals, iterate through the list and store the count of each kind of animal in a dictionary:

Example) Given the following list: ['lion', 'lion', 'boa', 'spider', 'spider']

A dictionary would be produced with the following: {'lion':2, 'boa':1, 'spider':2}

The function must return the dictionary from the previous requirement Comments and/or a docstring must be utilized to annotate the function implementation If the provided list is empty, print an appropriate error message and gracefully exit the program

2. Determine how many of the THIRD animal are in your Dictionary

While you can inspect your dictionary manually to find the third element, assume that you do not know what the dictionarys third element is.

A. In the main body of your code, create a list of animals of your choosing and store the list in a variable.

The list must contain at least four (4) total animals. (e.g. lion, lion, boa, manatee). The list may contain more than four total animals if you wish.

The list must contain at least three (3) different animals. The list may contain more than three different animals if you wish.

B. Call your function using the list created in step 2A as its argument.

Store the dictionary output from your function call in a new variable

C. Use a dictionary method, along with other concepts learned during this course to access the third element in your dictionary from Step 2B. Hint: You may want to use the list function.

Store the third animal in a new variable

3. Use the print() function to output the results

Use print() to display the third type of animal from your dictionary and how many of that type of animal you need to feed

Your result should look similar to this:

EXAMPLE: My zoo needs enough food for 2 lions.

REMINDER: Run your code and make sure it works as intended.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions

Question

Understand the purpose and implementation of cross-validation

Answered: 1 week ago

Question

=+Are the contracts enforceable?

Answered: 1 week ago