2016-12-02 5 views
0

クラス/メソッドを使用してレストランを作るプログラムを作成しようとしています。レストランを作ることで、私は彼らの名前、彼らが提供する食べ物の種類、そしていつ開くのかを言います。リストからアイテムを印刷するにはどうしたらいいですか?

私はそれを成功させましたが、今は親クラス(Restaurant)から継承し、子クラス(IceCreamStand)を作成するアイスクリームスタンドを作成しようとしています。私の問題は、アイスクリームフレーバーのリストを属性(flavor_options)に保存して印刷すると、そのリストの括弧で囲んだリストが印刷されることです。

リスト内の項目を通常の文章形式で印刷したいだけです。どのような助けも大変ありがとうございます!

#!/usr/bin/python 

    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. 
     else: 
      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) 
print(icecreamstand.describe_restaurant()) 
icecreamstand.flavors.list_of_flavors() 

restaurant = Restaurant(' Dingos', 'Australian', 10) 
print(restaurant.describe_restaurant()) 

restaurant.update_served(200) 
restaurant.read_served() 

restaurant.increment_served(1) 
restaurant.read_served() 
+2

"" .join(flavor_options) – Eric

+2

使用 '」」.join(self.flavor_options)'代わりにSTR(...) 'の' – mitoRibo

+0

感謝ロット!それは今働く –

答えて

2

リストを1つの文字列に結合する場合は、.join()を使用します。

I.E.

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

", ".join(flavor_options) 

これは希望は、出力:

"Chocolate, Vanilla, Strawberry" 
+0

ありがとう、それは仕事をした –

関連する問題