Question: Part 1 ====== distributeBag() function ------------------------ Read the function header to understand what this function does. Pay particular attention to its preconditions and postconditions. You

Part 1 ====== distributeBag() function ------------------------ Read the function header to understand what this function does. Pay particular attention to its preconditions and postconditions. You need to add your code to this function where indicated. Do not change any of its existing code. Note that this function's return statement returns 2 objects: The red bag and the blue bag objects. Returning multiple objects in a single return statement is a unique Python feature. The balls --------- The balls in the bags are objects of class Ball. This class is provided under the assignment in the course web page. Also provided there is a ball tester, which makes it easy to see how to use a ball. A red ball's color is the string "red". A blue ball's color is the string "blue". Moving the balls ---------------- Moving the balls means they need to end up in the right bag. It also means they should not be in the starting bag after your code completes. For each test case, a reference to the starting bag is passed in as a function parameter. Changes you make to this bag parameter result in changes to the bag used at the point of call. This is because parameters in Python are passed by reference, rather than by copied value. Your code should be general enough to handle all 3 sets of test data. Do NOT write 3 separate blocks of code, one for each specific test set. Instead, your single solution should work for any of these test cases. You should use a for loop on the original mixed bag. You do NOT need to remove the balls from the mixed bag as you see them. You can wait until after all the ball references have been added to the unicolor bags. Using references is a shallow copy of the balls. This is OK here because you will be removing the ball references from the mixed bag. This means there will not be any duplicate references in differebt bags to worry about. Keep it simple -------------- Do not overthink/overcomplicate this. Solutions are simple and easy to understand. There is more than one possible coding solution. Part 2 ====== printBag() function ------------------- This function takes a bag as a paramater. Look at the expected output document to see what it is supposed to print. It must iterate through the given bag. Each item must be printed on a separate line. To get a string version of a ball item, just use str(item). Notice that it must print "empty" if the bag is empty. Notice that it must print a blank line after the bag output. use python for this program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!