Does someone know, how can I use an Enum as class constructor parameter?
I have created such class:
class Coin(Cash, Enum):
onePenny = 1
twoPens = 2
fivePens = 5
ones = 0
twos = 0
fives = 0
def __init__(self, val):
if val == onePenny:
Cash.value = onePenny.value
Coin.ones += 1
elif val == twoPens:
Cash.value = twoPens.value
Coin.twos += 1
else:
print('Not existing coin.')
When I'm trying to create an object, I get the NameError:
NameError: name 'onePenny' is not defined
How to fix it?