Question: Implement the roll _ dice function in hog.py . It takes two arguments: a positive integer called num _ rolls giving the number of times

Implement the roll_dice function in hog.py. It takes two arguments: a positive integer called num_rolls giving the number of times to roll a die and a dice function. It returns the number of points scored by rolling the die that number of times in a turn: either the sum of the outcomes or 1(Sow Sad).
Sow Sad. If any of the dice outcomes is a 1, the current player's score for the turn is 1.
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 Sow Sad happens in the middle of rolling. By doing so, you will correctly simulate rolling all the dice together (and the user interface will work correctly).
Note: The roll_dice function, and many other functions throughout the project, makes use of default argument valuesyou 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:
python3 ok -q 01-u
Note: You will not be able to test your code using ok until you unlock the test cases for the corresponding question.
Write code and check your work:
Once you are done unlocking, begin implementing your solution. You can check your correctness with:
python3 ok -q 01

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!