Problem 2 (300pts)
Implement picky_piggy
, which takes the opponent's current score and returns the number of points scored by rolling 0 dice.
- Picky Piggy. A player who chooses to roll zero dice scores the \( n \)-th digit of the decimal expansion of \( 1/21 (0.04761904\dots) \) where \( n \) is the opponent's score. As a special case, if \( n \) is 0, the player scores only 1 point.
The goal of this question is for you to practice retrieving the digits of a number, so it may be helpful to keep in mind the techniques used in previous assignments for digit iteration.
However, your code should not use str
, lists, or contain square brackets [ ]
in your implementation.
Aside from this constraint, you can otherwise implement this function how you would like to.
Note: Remember to remove the
"*** YOUR CODE HERE ***"
string from the function once you've implemented it so that you're not getting an unintentional str check error.If the syntax check isn't passing on the docstring, try upgrading your Python version to 3.8 or 3.9. It seems that the docstring being included in the check is specific to Python version 3.7, so updating your Python version should resolve the issue.
Hint: The decimal expansion of \( 1/21 \) is a 6-digit repeating decimal with the digits \( 047619 \). Therefore, the 2nd digit is the same as the 8th digit, the 14th, 20th, 26th, 32nd, etc.
Before writing any code, unlock the tests to verify your understanding of the question.
$ python ok -q 02 -u
Once you are done unlocking, begin implementing your solution. You can check your correctness with:
$ python ok -q 02
You can also test picky_piggy
interactively by entering python -i hog.py
in the terminal and then calling picky_piggy
with various inputs.