-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathability_score.py
More file actions
30 lines (24 loc) · 834 Bytes
/
ability_score.py
File metadata and controls
30 lines (24 loc) · 834 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
29
30
from random import randint
class AbilityScore:
"""Class to represent one ability score """
def __init__(self):
""" Roll 1d6 4 times and take the best
3 to generate an ability score. """
# First roll 1d6 4 times.
rolls = []
for index in range(4):
rolls.append(randint(1, 6))
# Then add the 3 highest.
self.score = 0
lowest = 6
for roll in rolls:
self.score += roll
if roll < lowest:
lowest = roll
self.score -= lowest
def modifier(self):
""" Based on the score, determine the modifier. """
return self.score // 2 - 5
def print(self):
""" Print the score (used for debugging purposes). """
print(self.score)