0

I have these classes:

class Animal(abc.ABCMeta):
    @abc.abstractmethod
    def speak(self):
        raise NotImplementedError()

    def speak_twice(self):
        self.speak()
        self.speak()

class Cat(Animal):        
    def speak(self):
        print("Meow")

class Dog(Animal):    
    def speak(self):
        print("Voff")

And the outcome is this:

Meow
Meow

when I use buster.speak_twice()

I want the outcome to be this:

"Meow Meow"

I've tried changing a lot in the speak_twice function, like making the 2 different speak to str() and returning it and I've tried to change it to print.

Cœur
  • 37,241
  • 25
  • 195
  • 267
kreqq_
  • 43
  • 1
  • 9
  • 2
    You can't do what you want without changing how the `speak()` methods work. Those functions use `print()` to write directly to the terminal, they don't *return* their value to the caller. You'd have to change those to use `return 'Meow'` and `return 'Voff'` instead, so you can then use those return values and produce a new string. – Martijn Pieters Oct 11 '16 at 09:36
  • Thanks, works like a charm. – kreqq_ Oct 11 '16 at 09:39

0 Answers0