forked from exercism/python-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnd_character.py
More file actions
28 lines (20 loc) · 801 Bytes
/
dnd_character.py
File metadata and controls
28 lines (20 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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