Make a class named Fruit with a data member to calculate the number of fruits in a basket. Create two other class named Apples and Mangoes to calculate the number of apples and mangoes in the basket. Print the number of fruits of each type and the total number of fruits in the basket.
class fruit:
def __init__(self,aples,mangoes):
self.aples = aples
self.mangoes = mangoes
def add(self):
all_fruit = self.aples + self.mangoes
fruit_dict = {'aples':self.aples,'mangoes':self.mangoes}
print('number of all friuts ',all_fruit,'muber of each fruit :',fruit_dict)
class apless:
def __init__(self,aples):
self.aples = aples
def returnn (self):
return self.aples
class mango:
def __init__(self,mangoes):
self.mangoes = mangoes
def returnn(self):
return self.mangoes
ap = apless(int(input(' apples:')))
mg = mango(int(input(' mango:')))
fr = fruit(ap.returnn(),mg.returnn())
fr.add()
Comments
Leave a comment