Question
Please help with this Python question: In this exercise, you won't edit any of your code from the Burrito class. Instead, you're just going to
Please help with this Python question:
In this exercise, you won't edit any of your code from the Burrito class. Instead, you're just going to write a function to use instances of the Burrito class. You don't actually have to copy/paste your previous code here if you don't want to, although you'll need to if you want to write some test code at the bottom.
Write a function called total_cost. total_cost should take as input a list of instances of Burrito, and return the total cost of all those burritos together as a float.
Hint: Don't reinvent the wheel. Use the work that you've already done. The function can be written in only five lines, including the function declaration.
Hint 2: The exercise here is to write a function, not a method. That means this function should *not* be part of the Burrito class. If you'd like to use the test code, paste your previous code here.
Write your new function here.
Below are some lines of code that will test your function. You can change the value of the variable(s) to test your function with different inputs. Note that these lines will ONLY work if you copy/paste your Burrito, Meat, Beans, and Rice classes in.
If your function works correctly, this will return print: 28.0 burrito_1 = Burrito("tofu", True, "white", "black") burrito_2 = Burrito("steak", True, "white", "pinto", extra_meat = True) burrito_3 = Burrito("pork", True, "brown", "black", guacamole = True) burrito_4 = Burrito("chicken", True, "brown", "pinto", extra_meat = True, guacamole = True) burrito_list = [burrito_1, burrito_2, burrito_3, burrito_4] print(total_cost(burrito_list))
FYI this is my previous code:
class Meat: def __init__(self, value=False): self.set_value(value) def get_value(self): return self.value def set_value(self, value): if value in ["chicken", "pork", "steak", "tofu"]: self.value = value else: self.value = False class Rice: def __init__(self, value=False): self.set_value(value) def get_value(self): return self.value def set_value(self, value): if value in ["brown", "white"]: self.value = value else: self.value = False class Beans: def __init__(self, value=False): self.set_value(value) def get_value(self): return self.value def set_value(self, value): if value in ["black", "pinto"]: self.value = value else: self.value = False # Add and modify your code here! class Burrito(Meat, Rice, Beans): def __init__(self, meat, to_go, rice, beans, extra_meat=False, guacamole=False, cheese=False, \ pico=False, corn=False): self.meat = Meat(meat) self.to_go = to_go self.rice = Rice(rice) self.beans = Beans(beans) self.extra_meat = extra_meat self.guacamole = guacamole self.cheese = cheese self.pico = pico self.corn = corn def get_meat(self): return self.meat.get_value() def get_to_go(self): return self.to_go def get_rice(self): return self.rice.get_value() def get_beans(self): return self.beans.get_value() def get_extra_meat(self): return self.extra_meat def get_guacamole(self): return self.guacamole def get_cheese(self): return self.cheese def get_pico(self): return self.pico def get_corn(self): return self.corn def set_meat(self, meat): self.meat.set_value(meat) def set_to_go(self, to_go): if type(to_go) == bool: self.to_go = to_go else: self.to_go = False def set_rice(self, rice): self.rice.set_value(rice) def set_beans(self, beans): self.beans.set_value(beans) def set_extra_meat(self, extra_meat): if type(extra_meat) == bool: self.extra_meat = extra_meat else: self.extra_meat = False def set_guacamole(self, guacamole): if type(guacamole) == bool: self.guacamole = guacamole else: self.guacamole = False def set_cheese(self, cheese): if type(cheese) == bool: self.cheese = cheese else: self.cheese = False def set_pico(self, pico): if type(pico) == bool: self.pico = pico else: self.pico = False def set_corn(self, corn): if type(corn) == bool: self.corn = corn else: self.corn = False def get_cost(self): cost = 5.0 regular_meat = ("chicken", "pork", "tofu") if self.meat.get_value() in regular_meat: cost += 1.0 if self.meat.get_value() == "steak": cost += 1.5 if self.extra_meat == True and self.meat.get_value() != False: cost += 1.0 if self.guacamole == True: cost += 0.75 return cost
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started