ive even printed it out
print("drawn: ",drawn_balls.append(random_element))
yet i still get none but how are no balls drawn??
i’ve now returned the drawn_balls, wait i’ve fixed it i put self.contents above to update the self.contents then i put self.contents by itself to my list.
self.contents.remove(random_element)
print("removed balls: ", self.contents)
This is because self.contents gets updated throughout the code, it’s like a variable almost that can get updated i know that, but why coudn’t i just put the whole thing it at once why did i need to break it up?
also im still getting none for drawn balls and therefore i am not passing test
code:
import copy
import random
class Hat:
def __init__(self, **kwargs):
self.contents = [k for k, v in kwargs.items() for _ in range(v)]
print("og list of balls: ",self.contents)
def draw(self, amount):
drawn_balls = self.contents
for _ in range(amount):
if len(self.contents) == 0:
break
random_element = random.choice(self.contents)
print("chosen NB: ",random_element)
self.contents.remove(random_element)
print("removed balls: ", self.contents)
print("drawn: ",drawn_balls.append(self.contents))
return drawn_balls
def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
pass
cur_draw = Hat(yellow = 3, blue = 2)
print("Final drawn balls:", cur_draw.draw(2))
output:
og list of balls: ['yellow', 'yellow', 'yellow', 'blue', 'blue']
chosen NB: yellow
removed balls: ['yellow', 'yellow', 'blue', 'blue']
drawn: None
Final drawn balls: ['yellow', 'yellow', 'blue', 'blue', [...]]
and what is that […] thing