Skip to content

Commit 1bb83ed

Browse files
authored
Forgot the code file for the dnd test! (#77)
1 parent 666c219 commit 1bb83ed

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from random import choice
2+
3+
4+
class Character:
5+
6+
def __init__(self):
7+
self.strength = self.calculate_points()
8+
self.dexterity = self.calculate_points()
9+
self.constitution = self.calculate_points()
10+
self.intelligence = self.calculate_points()
11+
self.wisdom = self.calculate_points()
12+
self.charisma = self.calculate_points()
13+
self.hitpoints = 10 + modifier(self.constitution)
14+
15+
def ability(self):
16+
score = choice([item for item in vars(self).values()])
17+
return score
18+
19+
def dice_roll(self):
20+
return choice(range(1, 7))
21+
22+
def calculate_points(self):
23+
rolls = sorted([self.dice_roll() for number in range(4)], reverse=True)
24+
return sum(rolls[:2])
25+
26+
27+
def modifier(constitution):
28+
return (constitution - 10) // 2

0 commit comments

Comments
 (0)