Question: from arraybag import ArrayBag from ball import Ball from linkedbag import LinkedBag from node import Node # Part 1 : def distributeBag ( bag )

from arraybag import ArrayBag
from ball import Ball
from linkedbag import LinkedBag
from node import Node
# Part 1:
def distributeBag(bag):
redBag = ArrayBag()
blueBag = ArrayBag()
# Iterate through the original bag:
for ball in bag:
# Inflate red balls and add them to the red bag:
if ball.getColor()== "red":
ball.setRadius(ball.getRadius()*2)
redBag.add(ball)
else:
# Add blue balls to the blue bag:
blueBag.add(ball)
# Empty the original bag:
bag.clear()
return redBag, blueBag
# Part 2:
def printBag(bag):
if bag.isEmpty():
print("empty")
else:
for item in bag:
print(item)
print() # Print a blank line after the contents
# Part 3:
def removeDuplicates(bag):
while True:
count =0
for item in bag:
count +=1
if count >1:
bag.remove(item)
break
else:
return
# Test Cases:
# Test 1:
print("Test 1:")
bag1= ArrayBag([Ball("red",10),
Ball("red",11),
Ball("red",12),
Ball("blue",15),
Ball("blue",15),
Ball("blue",15)])
print("Original mixed bag:")
printBag(bag1)
redBag, blueBag = distributeBag(bag1)
print("Red bag:")
printBag(redBag)
print("Blue bag:")
printBag(blueBag)
print("Final mixed bag:")
printBag(bag1)
# Test 2:
print("Test 2:")
bag2= ArrayBag([Ball("red",201),
Ball("red",201),
Ball("red",202),
Ball("red",202)])
print("Original mixed bag:")
printBag(bag2)
redBag, blueBag = distributeBag(bag2)
print("Red bag:")
printBag(redBag)
print("Blue bag:")
printBag(blueBag)
print("Final mixed bag:")
printBag(bag2)
# Test 3:
print("Test 3:")
bag3= ArrayBag()
print("Original mixed bag:")
printBag(bag3)
redBag, blueBag = distributeBag(bag3)
print("Red bag:")
printBag(redBag)
print("Blue bag:")
printBag(blueBag)
print("Final mixed bag:")
printBag(bag3)
# Test 4:
print("Test 4:")
bag4= LinkedBag(["apple",
"apple",
"banana",
"kiwi",
"cantaloupe",
"pear",
"banana",
"orange",
"orange",
"cantaloupe",
"apple",
"lemon",
"lime",
"lime"])
print("Original bag with duplicates:")
printBag(bag4)
removeDuplicates(bag4)
print("Bag after removing duplicates:")
printBag(bag4)
I need to know what the problem is and how fix this
 from arraybag import ArrayBag from ball import Ball from linkedbag import

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!