1

I think I might not have explained my question clearly. I apologise for that. I will try again.

I have a parent class with certain attributes:

class Restaurant():
'This is the restaurant class'

def __init__(self, name, cuisine_type):
    self.name = name
    self.cuisine_type = cuisine_type

Then I have a child class inheriting all the parent's attributes and adding a new one:

class IceCreamStand():

def __init__(self, *flavor):
    'Attributes of parent class initialised'
    self.flavor = flavor

Now I try printing a list of of flavours stored in the attribute flavor:

def desc_flavor(self):
    print('This Ice_Cream shop has ' + self.flavor + ' flavors')

flavor1 = IceCreamStand('Mango', 'Raspberry', 'Coffee', 'Vanilla')

If I use concat I get the message saying that the name is not defined.

My apologies for not explaining the problem correctly the first time and thanks for all the help.

enriquelc
  • 69
  • 7

3 Answers3

1
class IceCreamStand(Restaurant):
      def __init__(self,restaurant_name, cuisine_type):
          super().__init__(restaurant_name, cuisine_type)
         
      def describe_flavors(self,*flavors):
          print(f'{self.restaurant_name} has the following flavors:')
          for self.flavor in flavors:
              print(f'-{self.flavor}')
           
restaurant =IceCreamStand('DQ','ice cream')
restaurant.describe_restaurant()
restaurant.describe_flavors('Chocolate','Mango', 'Raspberry', 'Coffee', 'Vanilla')
Lynn_Feng
  • 21
  • 4
  • Welcome to StackOverflow. While this code may answer the question, providing additional context regarding *how* and/or *why* it solves the problem would improve the answer's long-term value. – Sven Eberth Jul 07 '21 at 22:19
0

Try using the below code:

def __init__(self, *attribute1):
    self.atributte1 = attribute1
Astik Gabani
  • 541
  • 1
  • 4
  • 11
0

Use Arbitrary argument list. See this answer.

Example:

li = []
def example(*arg):
    li = list(arg)
    print(li)

example('string1', 'string2', 'string3')
abhiarora
  • 8,763
  • 5
  • 30
  • 50