所以,基本上我的代码在打印我希望它打印的语句后打印 None 。我怎样才能阻止这个 None 打印
class Panda:
def __init__(self,name,gender,age):
self.name=name
self.gender=gender
self.age=age
def sleep(self,time=None):
self.time=time
if self.time!=None:
if self.time>=3 and self.time<=5:
self.food='Mixed Veggies'
if self.time>=6 and self.time<=8:
self.food='Eggplant & Tofu'
if self.time>=9 and self.time<=11:
self.food='Broccoli Chicken'
print('{} sleeps {} hours daily and should have {}'.format(self.name,self.time,self.food))
else:
print("{}'s duration is unknown thus should have only bamboo leaves".format(self.name))
panda1=Panda("Kunfu","Male", 5)
panda2=Panda("Pan Pan","Female",3)
panda3=Panda("Ming Ming","Female",8)
print(panda2.sleep(10))
print(panda1.sleep(4))
print(panda3.sleep())
慕斯709654
蝴蝶不菲
相关分类