Answers for "Kunfu Panda"

0

Kunfu Panda

class Panda:
    name=""
    gender=""
    age=0
    def __init__(self,name,gender,age): #initializes the values of name,age,gender of the Panda object
        self.name=name
        self.gender=gender
        self.age=age
    def sleep(self,time=None):
        if(time==None):     #if no argument is passed that means unknown time
            st=self.name+"'s duration is unknown thus should have only bamboo leaves"
        else:
            st=self.name+" sleeps "+str(time)+" hours daily and should have "
            if(time>=3 and time<=5):    #Mixed Veggies for panda who sleeps 3 to 5 hrs
                st=st+"Mixed Veggies"
            elif(time>=6 and time <=8): #Eggplant & Tofu for panda who sleeps 6 to 8 hrs
                st=st+"Eggplant & Tofu"
            elif(time>=9 and time<=11): #Broccali Chicken for panda who sleeps 9 to 11 hrs
                st=st+"Broccoli Chicken"
        #returns the diet plan of the panda object
        return st

panda1=Panda("Kunfu","Male",5)
panda2=Panda("Pan Pan","Female",3)
panda3=Panda("Ming Ming","Female",8)

print("{} is a {} Panda Bear who is {} years old".format(panda1.name,panda1.gender,panda1.age))
print("{} is a {} Panda Bear who is {} years old".format(panda2.name,panda2.gender,panda2.age))
print("{} is a {} Panda Bear who is {} years old".format(panda3.name,panda3.gender,panda3.age))

print("===========================")
print(panda2.sleep(10))
print(panda1.sleep(4))
print(panda3.sleep())
Posted by: Guest on July-25-2021

Browse Popular Code Answers by Language