1. Engineering
  2. Computer Science
  3. use the python language python37 is preferred...

Question: use the python language python37 is preferred...

Question details

rto

Before you implement the add operator, I want you to think about this scenerio a bit. Add combines two grocery lists into a newG i roceryList. Seems like it can be a simple operation with two grocery lists Tyou just take the items in one list and combine them with the second list and return a new GroceryList that has both objects. Lets take a look at that behavior. Lets see what happens to newList when we modify one of the original lists. What is going on in memory here? Notice how making a modification to secondList that the related objects in newList also changed. >>firstList Grocerylist >> firstlist.readListFromFile( gr.txt True >> secondList GroceryList ) >secondList.readListFromFile(gr.txt >>> secondList.multiplyAllitemsCount (2) >>> newList· firstList + secondLi st >>> print (str (newList)) milk:1.59:10sdairy 0ggs:1.99:2:dairy butter:l.99:1dairy beef:8.99:1:meat milk:1.59:20:dairy eggs:1.99:4 dairy butter:1.99:2:dairy beef:8.99:2:meat >>> #notice th@ counts above of the new list >>> #now go back to the second list and double the items aga >>secondList.multiplyAllItemsCount (2) True >>> #100k at the counts of the newList >> print (str (newList)) eggs:1.99:2:dairy butter:1.99:1:dairy beef:8.99:1:meat milk:1.59:40:dairy butter:1.99:4:dairy

grocery lists does not modify the items in the new grocery list. I think this is more desireable behavior. How can you implement this? Hint: How can you make a copy of the Groceryltem? >>> firstlist GroceryList > firstlist.readListFromFile(gr.txt) True >>>secondList-GroceryList O >>> secondtist.readListFromFile(gr.txt True >> secondList.multiplyallItemsCount (2) True >>> newList- firstList + secondList >>> print (str (newList) ) milk:1.59:10:dairy eggs:1.99:2:dairy butter:1.99:1:dairy beef:8.99:1:meat milk:1.59:20:dairy butter:1.99:2:dairy beof:8.99:2:meat >>> secondList.multiplyAllitemsCount (2) True milk:1.59:10:dairy butter:1.99:1:dairy beef:8.99:1:meat milk:1.59:20:dairy eggs:1.99:4:dairy butter:1.99:2:dairy beef:8.99:2:meat

Use the python language. Python3.7 is preferred.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution