Manolo Ribera Manolo Ribera - 8 months ago 48
Python Question

How can I print items from a list?

I am trying to create a program that uses classes and methods to makes a restaurant/s. By making a restaurant I mean it states their name, the type of food they serve, and when they open.

I have done that successfully, but now I am trying to create an ice cream stand that inherits from its parent class (

) and makes a child class (
). My problem is that when I store the list of ice cream flavors in an attribute (
), and print it, it prints the list with the brackets around it.

I just want to print the items inside the list in a regular sentence format. Any help is greatly appreciated, thanks!


class Restaurant(object):
def __init__(self, restaurant_name, cuisine_type, rest_time):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
self.rest_time = rest_time
self.number_served = 0

def describe_restaurant(self):
long_name = "The restaurant," + self.restaurant_name + ", " + "serves " + self.cuisine_type + " food"+ ". It opens at " + str(self.rest_time) + "am."
return long_name

def read_served(self):
print("There has been " + str(self.number_served) + " customers served here.")

def update_served(self, ppls):
self.number_served = ppls

if ppls >= self.number_served:
self.number_served = ppls # if the value of number_served either stays the same or increases, then set that value to ppls.
print("You cannot change the record of the amount of people served.")
# if someone tries decreasing the amount of people that have been at the restaurant, then reject themm.

def increment_served(self, customers):
self.number_served += customers

class IceCreamStand(Restaurant):
def __init__(self, restaurant_name, cuisine_type, rest_time):

super(IceCreamStand, self).__init__(restaurant_name, cuisine_type, rest_time)
self.flavors = Flavors()

class Flavors():
def __init__(self, flavor_options = ["coconut", "strawberry", "chocolate", "vanilla", "mint chip"]):
self.flavor_options = flavor_options

def list_of_flavors(self):
print("The icecream flavors are: " + str(self.flavor_options))

icecreamstand = IceCreamStand(' Wutang CREAM', 'ice cream', 11)

restaurant = Restaurant(' Dingos', 'Australian', 10)



Answer Source

You would want to use .join() to combine the list into a single string.


flavor_options = ['Chocolate','Vanilla','Strawberry']

", ".join(flavor_options)

This would output:

"Chocolate, Vanilla, Strawberry"