class Toy(object):
def play(self, toy):
''''Print squeak'''
print 'Squeak!'
class Dog(object):
def __int__(self, name):
'''Name a dog'''
self.name = name
def call(self, shout):
'''Return true if shout is exactly 'Here, n!', otherwise return False'''
return shout == 'Here, ' + str(self.name) + '!'
def play(self, toy, n):
'''Print 'Yip! ' followed by the output from toy.play on the same line.\
This happens n times and outputs are in separate lines. if n is \
negative, then n is treated as 0'''
if n < 0:
n = 0
for i in range(n):
t = Toy()
print 'Yip! ' + str(t.play(toy)),
There is a problem in the play function of Dog class.
The result are expected to be:
Yip! Squeak!
Yip! Squeak!
Yip! Squeak!
but the result I got is:
Squeak!
Yip! None Squeak!
Yip! None Squeak!
Yip! None
can anybody tell me what's wrong with my code?
Thx a lot :)