Write a program frog.py
that includes a definition for a class Frog
that defines a frog in terms of its common name ("bullfrog", "leopard frog", "peeper", etc.), its x-y location, and its vocalization ("ribbet", "croak", "peep", etc.) Include the methods getName()
, getLocation()
, jump()
, and vocalize()
for this class.
The methods getName()
, getLocation()
, and vocalize()
all return the state of their respective instance variables. The jump()
method changes the x
and y
locations of the Frog up or down by 1, randomly.
To make it easier to view the information about the frog, write a __str__()
method that returns a string representation of the frog data in the following format:
Frog[name=FrogName,location=FrogLoc,sound=FrogSound]
Then write a main()
function that creates a list of frogs and demonstrates the use of the methods in this class.
Example Output:
Creating frogs...
Here are all the frogs:
Frog[name=bullfrog,location=[0, 0],sound=ribbet]
Frog[name=leopard frog,location=[0, 1],sound=croak]
Frog[name=spring peeper,location=[-1, 0],sound=peep]
All the frogs are going to randomly jump...
Here are all the frogs now:
Frog[name=bullfrog,location=[-1, 1],sound=ribbet]
Frog[name=leopard frog,location=[0, 2],sound=croak]
Frog[name=spring peeper,location=[-1, 0],sound=peep]
Listen to the frogs!
ribbet
croak
peep