Question: URGENTTT PYTHON When you open a MatryoshkaDoll, you find a smaller MatryoshkaDoll inside it and a smaller MatryoshkaDoll inside that The smallest MatryoshkaDoll has no
URGENTTT PYTHON
When you open a MatryoshkaDoll, you find a smaller MatryoshkaDoll inside it and a smaller MatryoshkaDoll inside that The smallest MatryoshkaDoll has no dolls inside it.
Modify MatryoshkaDoll.getNumberOfSmallerDolls so that it returns, efficiently with respect to time used, the total number of MatryoshkaDoll that are contained inside that instance of the doll.
For example, MatryoshkaDoll(MatryoshkaDoll(None)).getNumberOfSmallerDolls should return 1 because the outer doll contains only 1 doll.
Here's the code
class MatryoshkaDoll: def __init__(self, innerdoll): self.innerdoll = innerdoll
def getNumberOfSmallerDolls(self): #TODO:Implement return -1
#Example method call. doll = MatryoshkaDoll(MatryoshkaDoll(None)) print(doll.getNumberOfSmallerDolls())
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
