本文主要是介绍python3:设计一个动物声音“模拟器”,希望模拟器可以模拟许多动物的叫声,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
class Simulator:def __init__(self):self.animal = Nonedef playsound(self,animal):#print(animal.getAnimalName()+"的声音")animal.cry()class Animal:def cry(self):print("cry:")def getAnimalName(self):print("getname:")class Dog(Animal):def cry(self):print("Wang,Wang…")def getAnimalName(self,name):return nameclass Cat(Animal):def cry(self):print("Miao,Miao…")def getAnimalName(self,name):print(name)return name
while True:try:num,nam = map(str,input().split())#print(num)#print(nam)if(num == "0"):#print(num)ss = Simulator()sss = Cat()ss.playsound(sss)elif(num == "1"):#print(num)ss = Simulator()sss = Dog()ss.playsound(sss)except:break;
这篇关于python3:设计一个动物声音“模拟器”,希望模拟器可以模拟许多动物的叫声的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!