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())

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source