Last active
October 27, 2017 15:47
-
-
Save arsho/59a2cb4f08cffa175738f38f1c85d912 to your computer and use it in GitHub Desktop.
Multiple Inheritance example using Python 3. The program requires pyttsx3. Install it using pip install pyttsx3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from speaker import Speaker | |
class Animal: | |
def eat(self): | |
print("It eats.") | |
def sleep(self): | |
print("It sleeps.") | |
class Bird(Animal): | |
def fly(self): | |
print("It flies in the sky.") | |
def sing(self): | |
print("It sings.") | |
def speak(self, text = "No sound is found."): | |
print("It can not speak but can write it.") | |
print(text) | |
class SingingBird(Speaker, Bird): | |
def __init__(self, birdName = "Bird Name"): | |
self.birdName = birdName | |
def printBirdName(self): | |
print("This is a {birdName}!".format(birdName = self.birdName)) | |
print(SingingBird.__bases__) | |
duck = SingingBird("Duck") | |
duck.printBirdName() | |
duck.eat() | |
duck.sleep() | |
duck.fly() | |
duck.sing() | |
duck.speak("Quack quack, quack quack, quack quack") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyttsx3 | |
class Speaker: | |
engine = pyttsx3.init() | |
def speak(self, text = "No sound is found."): | |
print(text) | |
self.engine.say(text) | |
self.engine.runAndWait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment