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 :
def distributeBagbag:
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.setRadiusballgetRadius
redBag.addball
else:
# Add blue balls to the blue bag:
blueBag.addball
# Empty the original bag:
bag.clear
return redBag, blueBag
# Part :
def printBagbag:
if bag.isEmpty:
printempty
else:
for item in bag:
printitem
print # Print a blank line after the contents
# Part :
def removeDuplicatesbag:
while True:
count
for item in bag:
count
if count :
bag.removeitem
break
else:
return
# Test Cases:
# Test :
printTest :
bag ArrayBagBallred
Ballred
Ballred
Ballblue
Ballblue
Ballblue
printOriginal mixed bag:"
printBagbag
redBag, blueBag distributeBagbag
printRed bag:"
printBagredBag
printBlue bag:"
printBagblueBag
printFinal mixed bag:"
printBagbag
# Test :
printTest :
bag ArrayBagBallred
Ballred
Ballred
Ballred
printOriginal mixed bag:"
printBagbag
redBag, blueBag distributeBagbag
printRed bag:"
printBagredBag
printBlue bag:"
printBagblueBag
printFinal mixed bag:"
printBagbag
# Test :
printTest :
bag ArrayBag
printOriginal mixed bag:"
printBagbag
redBag, blueBag distributeBagbag
printRed bag:"
printBagredBag
printBlue bag:"
printBagblueBag
printFinal mixed bag:"
printBagbag
# Test :
printTest :
bag LinkedBagapple
"apple",
"banana",
"kiwi",
"cantaloupe",
"pear",
"banana",
"orange",
"orange",
"cantaloupe",
"apple",
"lemon",
"lime",
"lime"
printOriginal bag with duplicates:"
printBagbag
removeDuplicatesbag
printBag after removing duplicates:"
printBagbag
I need to know what the problem is and how fix this
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
