Hi there,
I'm working on
the Wheel class of Roulette game and I'm struggling to to figure out how to implement the
addOutcome method of the
Wheel class. The requirement here is to add a given
Outcome object to the
Bin instance with the given number.
Since each Bin object is a frozenset (immutable), does it mean we need to convert it into a set, then add a new Outcome object to it and then reconvert it back into a new Bin object inside the self.bins tuple of the Wheel object?
Here, I'm using the .union() method to generate a new frozenset with the added Outcome. However, since the self.bins itself is a tuple (immutable) so changing the Bin object inside it is also not possible.
I'm confused here and would really appreciate any help on how to implement this.
Below is my current code.
class Bin(frozenset):
pass
class Wheel:
def __init__(self) -> None:
self.bins = tuple(Bin() for _ in range(38))
def addOutcome(self, number: int, outcome: Outcome) -> None:
"""
Add the given Outcome object to the Bin instance with the given number
"""
# Does not work since self.bins is an immutable tuple
self.bins[number] = self.bins[number].union(outcome)