ow do I create a class Battle, with the following instance attributes: iron_chef: a Chef object challenger: a Chef object secret_ingredient: a string (the ingredient to be used by the chefs in this battle) dishes: a list of Dish objects outcome: an empty string The Battle class should also have the following instance method: conclude: Make the critics rate the dishes in the battle, and then set the outcome attribute to either 'iron_chef', 'challenger', or 'tie' based on the results. (Whichever chef gets a higher total rating across all dishes is declared the winner.) SO basically rate every dish (by calling rate_dish ON a specific dish), and keep track of the score of each chef - so you need to check which chef is responsible for each dish basically. BELOW IS THE CODE I HAVE -------------------------------------- import random class Chef: def __init__(self, name, record, cuisine): ''' (string, tuple, string) -> Chef ''' self.name = name self.record = record self.cuisine = cuisine[:] def __str__(self): s = "Chef name: \t" + self.name s += "\nRecord: \t" + str(self.record) s += "\nCuisine: \t" + self.cuisine return s class Dish: def __init__(self, name, ingredients, chef, ratings): '''(string, list, chef, list) -> Dish''' self.name = name self.ingredients = ingredients[:] self.chef = chef self.ratings = ratings def rate_dish(self): if len(self.ratings) >= 4: self.ratings = [] for i in range(4): self.ratings.append(random.randint(0, 10)) def __str__(self): s = "Dish name: \t" + self.name s += "\nIngredients:\n" for i in self.ingredients: s += "\t\t-" + str(i) + "\n" s += "Chef: \t\t" + str(self.chef.name) + "\n" s += "Ratings: \t" + str(self.ratings) return s class Battle: def __init__(self, iron_chef, challenger, secret_ingredient, dishes, outcome=''): '''(Chef, Chef, string, list, string) -> Battle''' self.iron_chef = iron_chef self.challenger = challenger self.secret_ingredient = secret_ingredient self.dishes = dishes self.outcome = outcome
How do I create a class Battle, with the following instance attributes:
iron_chef: a Chef object
challenger: a Chef object
secret_ingredient: a string (the ingredient to be used by the chefs in this battle)
dishes: a list of Dish objects
outcome: an empty string
The Battle class should also have the following instance method:
conclude: Make the critics rate the dishes in the battle, and then set the outcome attribute to either 'iron_chef', 'challenger', or 'tie' based on the results. (Whichever chef gets a higher total rating across all dishes is declared the winner.) SO basically rate every dish (by calling rate_dish ON a specific dish), and keep track of the score of each chef - so you need to check which chef is responsible for each dish basically.
BELOW IS THE CODE I HAVE
--------------------------------------
import random
class Chef:
def __init__(self, name, record, cuisine):
''' (string, tuple, string) -> Chef '''
self.name = name
self.record = record
self.cuisine = cuisine[:]
def __str__(self):
s = "Chef name: \t" + self.name
s += "\nRecord: \t" + str(self.record)
s += "\nCuisine: \t" + self.cuisine
return s
class Dish:
def __init__(self, name, ingredients, chef, ratings):
'''(string, list, chef, list) -> Dish'''
self.name = name
self.ingredients = ingredients[:]
self.chef = chef
self.ratings = ratings
def rate_dish(self):
if len(self.ratings) >= 4:
self.ratings = []
for i in range(4):
self.ratings.append(random.randint(0, 10))
def __str__(self):
s = "Dish name: \t" + self.name
s += "\nIngredients:\n"
for i in self.ingredients:
s += "\t\t-" + str(i) + "\n"
s += "Chef: \t\t" + str(self.chef.name) + "\n"
s += "Ratings: \t" + str(self.ratings)
return s
class Battle:
def __init__(self, iron_chef, challenger, secret_ingredient, dishes, outcome=''):
'''(Chef, Chef, string, list, string) -> Battle'''
self.iron_chef = iron_chef
self.challenger = challenger
self.secret_ingredient = secret_ingredient
self.dishes = dishes
self.outcome = outcome

Step by step
Solved in 2 steps with 1 images









