Handling **kwargs in python

Tell us what’s happening:
I’m not sure how to deal with the parameters they provide me
hat = prob_calculator.Hat(blue=4, red=2, green=6) because they’re not strings and I can’t use the split methode.

Here’s what i’ve tried

class Hat:

  def __init__(self, *args):
    self.contents = []
    for arg in args:
      n = int(arg.split('=')[1])
      for i in range(n):
        self.contents.append(arg.split('=')[0])

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36

Challenge: Probability Calculator

Link to the challenge:

The syntax that you are seeing is ‘keyword arguments’. You have a good idea, but you are accessing the wrong type of arguments.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.