MCPcopy Create free account
hub / github.com/geekcomputers/Python / set_sides

Method set_sides

dice.py:16–28  ·  view source on GitHub ↗

Validates and sets the number of sides. A physical die must have at least 4 sides.

(self, num_sides)

Source from the content-addressed store, hash-verified

14 self.set_sides(sides)
15
16 def set_sides(self, num_sides):
17 """
18 Validates and sets the number of sides.
19 A physical die must have at least 4 sides.
20 """
21 if isinstance(num_sides, int) and num_sides >= 4:
22 if num_sides != self.sides:
23 print(f"Changing sides from {self.sides} to {num_sides}!")
24 else:
25 print(f"Sides already set to {num_sides}.")
26 self.sides = num_sides
27 else:
28 print(f"Invalid input: {num_sides}. Keeping current value: {self.sides}")
29
30 def roll(self):
31 """Returns a random integer between 1 and the number of sides."""

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected