Question
In my dessertshop.py, in my Order class I have a __str__ method that prints to the terminal a table of all my dessert items in
In my dessertshop.py, in my Order class I have a __str__ method that prints to the terminal a "table" of all my dessert items in a nice formatted way. I have gotten rid of unnecessary commas in this __str__ method to make it look better. The output of this __str__ method is:
Name Quantity Unit Price Cost Tax
Gummy Bears 0.5lbs $4/lb $2.00 $0.14
Oatmeal Raisin Cookies 2 Cookies $3.45/dozen $0.57 $0.04
Pistachio Ice Cream 2 scoops $0.79/scoop $1.58 $0.11
Hot Fudge Vanilla Sundae 3 scoops $0.69/scoop $3.36 $0.24
Hot Fudge 1 $1.29
In my main function I am trying to feed to my data empty list every row in the output above as a list of lists (every row will be a list with those respective elements in each list) so that then I can import the list 'data' into receipt.py.
How can I iterate through this output, separate each element in each row as elements in a list, and created a list of lists in my data empty list?
dessertshop.py import dessert import receipt class Order(): definit_(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) deflen_(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): order_str "Name Quantity Unit Price Cost Tax " for dessert in self.order: order_strstr(dessert) + " "
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To iterate through the output provided by the str method in the Order class of your dessertshoppy fi...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