Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using python and show it was working In the same module/file, write a function processAnimals that takes one argument, the name of an input file.

using python and show it was working

In the same module/file, write a function processAnimals that takes one argument, the name of an input file. The function returns the list of animals created or an empty list if the file didn't contain any lines. The input file contains zero or more lines with the format: species, language, age where species is a string representing an animal's species, language is a string representing an animal's language, and age is an integer representing an animal's age. The items on each line are separated by commas. The processAnimals function should read all lines in the file, creating an Animal object for each line and placing the object into a list. The function also prints to output the result of calling the method speak on each object in the list it created. Don't forget to close the input file. The information below shows how you would call the function processAnimals on an example file. Please note that your implementation should work on any file with the specified format, not just the one provided as a test case:

>>> processAnimals('animals.txt')

I am a 8 year-old cat and I meow.

I am a 22 year-old dog and I bark.

I am a 2 year-old bat and I use sonar.

[Animal('cat','meow',8), Animal('dog','bark',22), Animal('bat','use sonar',2)]

>>> processAnimals('animals.txt')==[Animal('cat','meow',8), Animal('dog','bark',22), Animal('bat','use sonar',2)]

I am a 8 year-old cat and I meow.

I am a 22 year-old dog and I bark.

I am a 2 year-old bat and I use sonar.

True

>>>

this is animals text file

image text in transcribed

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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago