-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroll.py
More file actions
31 lines (25 loc) · 731 Bytes
/
roll.py
File metadata and controls
31 lines (25 loc) · 731 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
31
#!/usr/bin/env python3
"""a dice roll program
"""
import colors as c
import time
import random
def roll(howmany=1,sides=6):
"""Returns the result from rolling 'hawmany' of 'sides'-sides dice"""
total = 0
for count in range(howmany):
total += random.randint(1,sides)
return total
def parse(text):
"""Parses traditional dice notation (ex: 3d6)"""
howmany, sides = text.split('d')
return (int(howmany), int(sides))
def parse_roll(text):
"""Parses traditional dice notation and then rolls (ex: 3d6)"""
howmany, sides = text.split('d')
return (int(howmany), int(sides))
if __name__ == '__main__':
while True:
print(c.clear)
print(roll())
time.sleep(0.5)