Skip to content

Commit c4cede4

Browse files
committed
Initial structure, coin flips.
1 parent 410e3b6 commit c4cede4

File tree

9 files changed

+480
-0
lines changed

9 files changed

+480
-0
lines changed

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
none: help
2+
3+
help:
4+
@echo "dicebox: Roll dice, flip coins, and simulate other decision-making methods."
5+
@echo
6+
@echo "run Run dicebox directly from this repository."
7+
@echo "lint Run pylint3 on the dicebox package."
8+
@echo "test Run pytests for dicebox."
9+
10+
lint:
11+
@pylint3 --rcfile=pylintrc dicebox
12+
13+
run:
14+
@python3 -m dicebox
15+
16+
test:
17+
@python3 -m pytest dicebox
18+
19+
.PHONY: lint run test

dicebox/__init__.py

Whitespace-only changes.

dicebox/__main__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
dicebox 1.0
3+
Main module.
4+
5+
Author(s): Jason C. McDonald
6+
"""
7+
8+
# Process command line arguments.
9+
import sys
10+
from dicebox.items import coins
11+
12+
def coin(args):
13+
"""
14+
Calls the coin function.
15+
"""
16+
17+
flips = 1
18+
# Make sure we have only one argument, an integer.
19+
if len(args) == 1:
20+
try:
21+
flips = int(args[0])
22+
except ValueError:
23+
print("Invalid number of coins (" + str(args[0]) + ") provided.")
24+
sys.exit(1)
25+
26+
coinjar = coins.CoinJar(flips)
27+
coinjar.flip()
28+
coinjar.display()
29+
30+
def main():
31+
"""
32+
The main function for dicebox.
33+
"""
34+
args = []
35+
if len(sys.argv) <= 1:
36+
print("Argument required.")
37+
sys.exit(1)
38+
elif len(sys.argv) >= 2:
39+
args = sys.argv[2:]
40+
41+
item = sys.argv[1]
42+
if item == "coin":
43+
coin(args)
44+
45+
if __name__ == "__main__":
46+
main()

dicebox/items/__init__.py

Whitespace-only changes.

dicebox/items/coins.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Coin [dicebox 1.0]
3+
4+
Author(s): Jason C. McDonald
5+
"""
6+
7+
import random
8+
9+
class CoinJar:
10+
"""
11+
A collection of one or more coins, which can be flipped.
12+
"""
13+
14+
def __init__(self, count=1):
15+
"""
16+
Initialize a jar of coins.
17+
"""
18+
# The list of coins, all Heads by default.
19+
self.__coins = [True] * count
20+
21+
def flip(self):
22+
"""
23+
Flip all coins in the CoinJar.
24+
True = Heads, False = Tails
25+
"""
26+
for i in range(0, len(self.__coins)):
27+
self.__coins[i] = random.choice([True, False])
28+
29+
def display(self):
30+
"""
31+
Show the results of the coin flip.
32+
"""
33+
for coin in self.__coins:
34+
if coin:
35+
print("Heads")
36+
else:
37+
print("Tails")

dicebox/items/dice.py

Whitespace-only changes.

dicebox/tests/__init__.py

Whitespace-only changes.

dicebox/tests/test_basic.py

Whitespace-only changes.

0 commit comments

Comments
 (0)