Uploaded by Turtle Man

Practice Lab Week 4

advertisement
PRACTICE LAB Week 4
Scenario:
ABC Pet Farm needs to manage its inventory of pet food to feed its staple of new born kitten and old cat.
You are hired to write a script to get the list of cat and identify the youngest cat and oldest cat to determine
the appropriate food to buy for the feeding programme.
The age of the cat are listed in Table 1:
Cat ID
C1
C2
C3
C4
C5
Cat Name
Tabby
Kitty
Tommy
Tikki
Tammy
Age
3
1
2
6
7
Table 1
Instructions:
Part 1:
1. Create a project script with the following name “PetShop”.
2. Create python class, Cat with the appropriate attributes, constructor and method/s to represent the
task specification.
Part 2:
1. Create python class, CatMonitor to represent task specification.
2. Write python code to declare the appropriate data structure to hold and represent the following:
a.
b.
c.
d.
Cat ID and Cat Name
Cat ID and Age
Series of Age
Series of Cat id
3. Write python code to add appropriate attributes and methods signature to hold and manage the
following information in the CatMonitor class.
a. Cat ID, Cat Name and Age reflected in Table 1.
b. Compute and return the average age in Table 1.
c. Compute and return the Cat with the oldest age.
d. Create a method to get new cat and its age from user.
Copyright, Institute of Technical Education
1
Part 3:
1. Write python code to declare the appropriate variable datatype to hold and represent the following
information
a)
b)
c)
d)
cat id
cat name
average age
oldest age
Part 4:
1. Write python code to instantiate object from the class.
2. Write python code to use the instantiated object to retrieve and display average age:
Total average age – 3.8
3. Write python code to call instantiated object to retrieve and display cat id, cat name and age for the
oldest cat as follows:
Cat id : C5
Cat Name : Tammy
Age : 4
Part 5:
1. Write python code to call the instantiated object to prompt user to enter the following new cat id,
cat name and age as follows:
Cat id = C6
Cat Name = MooMoo
Age = 3
2. Write python code to call the instantiated object to retrieve and display the new average age
follows:
Total average age = 3.67
---End---
Copyright, Institute of Technical Education
2
Download