Problem 1 (200pts)

Implement the roll_dice function in hog.py. It takes two arguments: a positive integer called num_rolls giving the number of dice to roll and a dice function. It returns the number of points scored by rolling the dice that number of times in a turn: either the sum of the outcomes or 1 (due to Pig Out).

To obtain a single outcome of a dice roll, call dice(). You should call dice() exactly num_rolls times in the body of roll_dice.

Remember to call dice() exactly num_rolls times even if Pig Out happens in the middle of rolling. In this way, you correctly simulate rolling all the dice together.

Note: The roll_dice function, and many other functions throughout the project, makes use of default argument values -- you can see this in the function heading:

def roll_dice(num_rolls, dice=six_sided):
    ...

The argument dice=six_sided means that when roll_dice is called, the dice argument is optional. If no value for dice is provided, then six_sided is used by default.

For example, calling roll_dice(3, four_sided), or equivalently roll_dice(3, dice=four_sided), simulates rolling 3 four-sided dice, while calling roll_dice(3) simulates rolling 3 six-sided dice.


Understand the problem: Before writing any code, unlock the tests to verify your understanding of the question. Note: you will NOT be able to test your code using ok until you unlock the test cases for the corresponding question.

$ python ok -q 01 -u

Write code and check your work: Once you are done unlocking, begin implementing your solution. You can check your correctness with:

$ python ok -q 01