I have created a class Dice where I have a function roll_die that rolls a dice, and a function roll_dice that rolls n number of dices. From this the program present the sum from the die or dices.
I have now tried to add a constructor that allows us to set number_of sides to also be able to determine the number of sides on the die or dice, the sides can be 4,6,8,12 or 20, if it is not specified how many sides it should be automatically continued with a six-sided dice.
But I still get an error message TypeError: __init__() missing 1 required positional argument: 'sides' when the number of pages is not specified, what did I do wrong?
class Dice:
def __init__(self, sides):
self.sides = sides
self.value = random.randint(1, self.sides)
def roll_die(self, sides):
return random.randint(1,sides)
def roll_dice(self,n):
sum = 0
for i in range(n):
sum += self.roll_die()
return sum
def number_of_dice(self, sides):
if sides == None:
sides = 6
elif sides not in (4,6,8,12,20):
print('The dice can only be of size 4,6,8,12 or 20')