Bowl is a Python class that models a container for Scoop objects. It stores scoops in an ordered self.scoops list, accepts multiple scoops through add_scoops, and displays their flavors through __repr__. section 9.6 section 9.7
A practical Bowl implementation separates shared policy from per-object state:
- Initialize self.scoops as an empty list so each Bowl owns its contents and preserves scoop order. section 9.7
- Define add_scoops(self, *new_scoops) to accept any number of Scoop instances and append them one at a time. section 9.7
- Put max_scoops = 3 on the class to express one shared limit instead of hardcoding the value throughout the implementation. section 9.12
- Check the current scoop count before adding; once three scoops exist, additional scoops are ignored. section 9.11
- Refer to self.max_scoops when subclasses may override the capacity, allowing one add_scoops implementation to support Bowl and BigBowl. section 9.17
Adding scoops
s1 = Scoop('chocolate') s2 = Scoop('vanilla') s3 = Scoop('persimmon') b = Bowl() b.add_scoops(s1, s2) b.add_scoops(s3) print(b) The bowl contains three Scoop objects, while its representation joins their flavor strings for display. A fourth scoop would be ignored after the capacity limit is reached. section 9.6 section 9.7 section 9.11
s1 = Scoop('chocolate')
s2 = Scoop('vanilla')
s3 = Scoop('persimmon')
b = Bowl()
b.add_scoops(s1, s2)
b.add_scoops(s3)
print(b)
Inspect the complete interaction sequence for constructing Scoop objects, adding them across multiple calls, and printing the Bowl. section 9.6
