Skip to content

Problem 3 (200pts)

实现take_turn函数。掷给定的dice num_rolls次,返回骰子在一回合中得到的分数。

take_turn的实现应调用roll_dicepicky_piggy

在编写任何代码之前,请解锁测试以验证您对问题的理解。

python ok -q 03 -u

解锁完成后,开始实现您的解决方案。您可以使用以下命令检查正确性:

python ok -q 03

Solutions

def take_turn(num_rolls, opponent_score, dice=six_sided):
    """Return the points scored for the turn rolling NUM_ROLLS dices when the
    opponent has OPPONENT_SCORE points.

    num_rolls:       The number of dice rolls that will be made.
    opponent_score:  The total score of the other player.
    dice:            A function that simulates a single dice roll outcome.
    """
    # BEGIN PROBLEM 3
    return picky_piggy(opponent_score) if num_rolls == 0 else roll_dice(num_rolls, dice)
    # END PROBLEM 3