Professional Documents
Culture Documents
Lab 10
Lab 10
Lab 10
Submission Due: End of laboratory class, submit the file on Moodle at least 10 minutes before
the end of laboratory class.
Instructions:
Students are instructed to go through the given Lab and attempt each question.
Task 1: Methods are functions defined inside the body of a class. They are used to define the behaviors
of an object
obj=Parrot()
obj.name
obj.age
# instance attributes
def __init__(self, name, age):
self.name = name
self.age = age
# instance method
def sing(self, song):
return "{} sings {}".format(self.name, song)
def dance(self):
return "{} is now dancing".format(self.name)
Task 2:
Add a new attribute color to the class Parrot.
Define the main method with the following requirements:
a. Create a 5 new objects of type Parrot. Store the objects into a list. The list will have 5
objects. Using for loop, print the color of all the parrots in the list. (Create a display
method inside class Parrot)
b. Search for parrots that are Orange colored. (Create a search function)
==============