Create a new class called Flower. Flower is subclassed from the Plant class; so
ID: 3767414 • Letter: C
Question
Create a new class called Flower. Flower is subclassed from the Plant class; so besides name, and leaves, it adds 2 new attributes; color, petals. Color is a string that contains the color of the flower, and petals is an int that has the number of petals on the flower. You should create an init method to setup the instance. With the init you should make an UNBOUND method call to plant to setup the name and height. In addition, create a method called pick_petal that decrements the number of petals on the flower.Explanation / Answer
class Plant:
num_known = 0
def __init__(self,common_name,latin_name=None):
self.latin_name = latin_name
self.common_name = common_name
Plant.num_known += 1
def __str__(self):
return "I am a plant (%s)!" % self.common_name
class Flower(Plant):
has_pedals = True
def __init__(self,common_name,npedals=5,pedal_color="red",latin_name=None):
## call the __init__ of the
Plant.__init__(self,common_name,latin_name=latin_name)
self.npedals=5
self.pedal_color = pedal_color
def __str__(self):
return "I am a flower (%s)!" % self.common_name
class A:
def __init__(self):
print "A"
class B(A):
def __init__(self):
A.__init__(self)
print "B"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.