“pengetikan bebek di Python” Kode Jawaban

pengetikan bebek di 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

pengetikan bebek di 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

pengetikan bebek di 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

Jawaban yang mirip dengan “pengetikan bebek di Python”

Pertanyaan yang mirip dengan “pengetikan bebek di Python”

Lebih banyak jawaban terkait untuk “pengetikan bebek di Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya