Tell us what’s happening:
Stuck on the part “The draw method should behave correctly when the number of balls to extract is bigger than the number of balls in the hat.”
I dont get it, how do I tackle this? My code is given below:
Your code so far
import copy
import random
class hat:
def __init__(self,red = None,orange = None,black = None,blue = None,pink = None,striped = None,yellow = None,green = None):
self.red = red
self.orange = orange
self.black = black
self.blue = blue
self.pink = pink
self.striped = striped
self.yellow = yellow
self.green = green
lst = {'red':red,
'orange':orange,
'black':black,
'blue' : blue,
'pink' : pink,
'striped' : striped,
'yellow' : yellow,
'green' : green
}
self.contents = []
for key,value in lst.items():
if value is not None :
self.contents += value*[str(key)]
self.copy = []
self.copy = self.contents.copy()
def draw(self,number):
self.hat_list = []
self.contents = self.copy.copy()
if number >= len(self.contents) :
self.contents.clear()
self.hat_list = (self.copy.copy())
else:
for i in range(number):
temp = self.contents.index(random.choice(self.contents))
self.hat_list.append(self.contents.pop(temp))
return self.hat_list
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Build a Probability Calculator Project - Build a Probability Calculator Project