“Ententipp in Python” Code-Antworten

Ententipp in Python

class Duck:
    def quack(self):
        print("Quaaaaaack!")
    def feathers(self):
        print("The duck has white and gray feathers.")

class Person:
    def quack(self):
        print("The person imitates a duck.")
    def feathers(self):
        print("The person takes a feather from the ground and shows it.")
    def name(self):
        print("John Smith")

def in_the_forest(duck):
    duck.quack()
    duck.feathers()

def game():
    donald = Duck()
    john = Person()
    in_the_forest(donald)
    in_the_forest(john)

game()
Shy Skunk

Ententipp in Python

class Person:
    def help(self):
        print("Heeeelp!")

class Duck:
    def help(self):
        print("Quaaaaaack!")

class SomethingElse:
    pass

def InTheForest(x):
    x.help()

donald = Duck()
john = Person()
who = SomethingElse()

for thing in [donald, john, who]:
    try:
        InTheForest(thing)
    except AttributeError:
        print 'Meeowww!'
Shy Skunk

Ententipp in Python

class Duck(object): 
   def quack(self): 
      print "Quack" 
 
class Mallard(object): 
    def quack(self): 
        print "Quack Quack" 
 
def shoot(bird): 
    bird.quack() 
 
for target in [Duck(), Mallard()]: 
   shoot(target)
Shy Skunk

Ähnliche Antworten wie “Ententipp in Python”

Fragen ähnlich wie “Ententipp in Python”

Weitere verwandte Antworten zu “Ententipp in Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen