From 1e44f3ee105ec0b87c3a9932710ee3d17a067f51 Mon Sep 17 00:00:00 2001 From: BethanyG Date: Fri, 27 Feb 2026 16:27:17 -0800 Subject: [PATCH] Forgot the code file for the dnd test! --- test/dnd-character/dnd_character.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/dnd-character/dnd_character.py diff --git a/test/dnd-character/dnd_character.py b/test/dnd-character/dnd_character.py new file mode 100644 index 0000000..65bf07c --- /dev/null +++ b/test/dnd-character/dnd_character.py @@ -0,0 +1,28 @@ +from random import choice + + +class Character: + + def __init__(self): + self.strength = self.calculate_points() + self.dexterity = self.calculate_points() + self.constitution = self.calculate_points() + self.intelligence = self.calculate_points() + self.wisdom = self.calculate_points() + self.charisma = self.calculate_points() + self.hitpoints = 10 + modifier(self.constitution) + + def ability(self): + score = choice([item for item in vars(self).values()]) + return score + + def dice_roll(self): + return choice(range(1, 7)) + + def calculate_points(self): + rolls = sorted([self.dice_roll() for number in range(4)], reverse=True) + return sum(rolls[:2]) + + +def modifier(constitution): + return (constitution - 10) // 2