Discussion Thread (W-10): What you learn Today

Number of replies: 49
In reply to First post

Re: Discussion Thread (W-10): What you learn Today

by Abu Salkin -
learn about polymorphism and implement a code with output:


code:

class Cat:
def __init__(self, name, age):
self.name = name
self.age = age

def info(self):
print(f"I am a cat. My name is {self.name}. I am {self.age} years old.")

def make_sound(self):
print("Meow")


class Dog:
def __init__(self, name, age):
self.name = name
self.age = age

def info(self):
print(f"I am a dog. My name is {self.name}. I am {self.age} years old.")

def make_sound(self):
print("Bark")


cat1 = Cat("Kitty", 2.5)
dog1 = Dog("Fluffy", 4)

for animal in (cat1, dog1):
animal.make_sound()
animal.info()
animal.make_sound()



output:
Meow
I am a cat. My name is Kitty. I am 2.5 years old.
Meow
Bark
I am a dog. My name is Fluffy. I am 4 years old.
Bark
In reply to First post

Re: Discussion Thread (W-10): What you learn Today

by Jannatul Fardus Armin 192-15-2802 -
I have to learn about polymorphism and implement a code with output
code:

class Cat:
def __init__(self, name, age):
self.name = name
self.age = age

def info(self):
print(f"I am a cat. My name is {self.name}. I am {self.age} years old.")

def make_sound(self):
print("Meow")


class Dog:
def __init__(self, name, age):
self.name = name
self.age = age

def info(self):
print(f"I am a dog. My name is {self.name}. I am {self.age} years old.")

def make_sound(self):
print("Bark")


cat1 = Cat("Kitty", 2.5)
dog1 = Dog("Fluffy", 4)

for animal in (cat1, dog1):
animal.make_sound()
animal.info()
animal.make_sound()



output:
Meow
I am a cat. My name is Kitty. I am 2.5 years old.
Meow
Bark
I am a dog. My name is Fluffy. I am 4 years old.
Bark
In reply to First post

Re: Discussion Thread (W-10): What you learn Today

by Al- Maruf 192-15-2821 -
OOP using Python: Operator overloading, Polymorphism, Handling exception, Named tuples, Using Card data types, design case study
In reply to First post

Re: Discussion Thread (W-10): What you learn Today

by Sumon Bala -
Today we have learn about polymorphism and implement a code
In reply to First post

Re: Discussion Thread (W-10): What you learn Today

by Arup pal -
Today we have learn about polymorphism and implement a code