Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -s flag for number of sides on a die #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions b9/rand.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def main():
)

# COMMIT 1: Add -s flag for number of sides on a die

parser.add_argument( "-s", "--sides", dest="sides", type=int, default=6, help="Number of sides on a die (max=20; ignored when flipping a coin)" )

args = parser.parse_args()

Expand Down Expand Up @@ -58,10 +58,10 @@ def flip_coin(iterations):
def roll_dice(iterations, sides):

# COMMIT 3: Restrict input range for dice iterations and sides

def roll_dice(iterations, sides): # COMMIT 2: Add dice rolling logic and output dice sum and sequence diceRecord, diceSum = [], 0 for i in range(iterations): roll = random.randint(1, sides) diceRecord.append(roll) diceSum += roll print("{} roll(s) of a {}-sided die resulted in a sum of {}:" .format(iterations, sides, diceSum)) print(*diceRecord, sep=', ')

# COMMIT 2: Add dice rolling logic and output dice sum and sequence

# COMMIT 3: Restrict input range for dice iterations and sides if iterations > MAX_ITERATIONS or iterations < 0: print("Number of rolls must be in the range [0 - {}]" .format(MAX_ITERATIONS)) return if sides > MAX_SIDES or sides < 1: print("Number of sides must be in the range [1 - {}]" .format(MAX_SIDES)) return

return

Expand Down