Answer to Question #343549 in Python for postbox

Question #343549

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.


1
Expert's answer
2022-05-22T18:14:18-0400
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS