Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

One of the files (dessert.py) creates all the templates for all 4 desserts we can create. We added a __str__ method to print to the

One of the files (dessert.py) creates all the templates for all 4 desserts we can create. We added a __str__ method to print to the terminal the information of the specific dessert formatted in a specific way, in this example below __str__ returns Candy formatted in a more readable way.

The second file, dessertshop.py, creates an Order from all the instances of desserts from dessert.py. 

The goal is to add another __str__ method in the Order class to ultimately format the candy I created and passed to myself order like this:

Gummy Bears0.25lbs$0.35/lb$0.09$0.01

How can I write the __str__ method here to format my instance of Candy towards the bottom of dessertshop.py?

    

dessertshop.py import dessert class Order(): def __init__(self): ***"default constructor that takes no arguments and instantiates the order instance variable to a new list of DessertItem."** self.order = [] def add(self, dessert): """takes a single DessertItem and adds it to the empty list 'order'.""" self.dessert = dessert self.order.append(dessert) def len_(self): ***"magic method that returns the number of items in the list 'order'.**** return len(self.order) def order_cost(self, cost_list): ***"Calculates and returns the total cost for all items in the order.""" return sum(cost_list) def order_tax(self, cost_list, tax_percent): ***"Calculates and returns the total tax for all items in the order.""" return cost_list * tax_percent # def _str_(self): >>>>>> This is where I need help < < pass

Step by Step Solution

3.38 Rating (160 Votes )

There are 3 Steps involved in it

Step: 1

Here is how you can write the str method in the Order class to format your ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems analysis and design

Authors: kenneth e. kendall, julie e. kendall

8th Edition

135094909, 013608916X, 9780135094907, 978-0136089162

More Books

Students also viewed these Programming questions

Question

How do certain genetic conditions affect motor control?

Answered: 1 week ago

Question

List the four guidelines for good display design.

Answered: 1 week ago

Question

Define natural-language interfaces. What is their major drawback?

Answered: 1 week ago