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_dicefunction, 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_sidedmeans that whenroll_diceis called, thediceargument is optional. If no value fordiceis provided, thensix_sidedis used by default.For example, calling
roll_dice(3, four_sided), or equivalentlyroll_dice(3, dice=four_sided), simulates rolling 3 four-sided dice, while callingroll_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