Yacht

From Exercism PythonMITOriginal pagePython1 class period1 exercise29 graded tests

README.md

Yacht

Introduction

Each year, something new is "all the rage" in your high school. This year it is a dice game: Yacht.

The game of Yacht is from the same family as Poker Dice, Generala and particularly Yahtzee, of which it is a precursor. The game consists of twelve rounds. In each, five dice are rolled and the player chooses one of twelve categories. The chosen category is then used to score the throw of the dice.

Instructions

Given five dice and a category, calculate the score of the dice for that category.

Note

You'll always be presented with five dice. Each dice's value will be between one and six inclusively. The dice may be unordered.

Scores in Yacht
CategoryScoreDescriptionExample
Ones1 × number of onesAny combination1 1 1 4 5 scores 3
Twos2 × number of twosAny combination2 2 3 4 5 scores 4
Threes3 × number of threesAny combination3 3 3 3 3 scores 15
Fours4 × number of foursAny combination1 2 3 3 5 scores 0
Fives5 × number of fivesAny combination5 1 5 2 5 scores 15
Sixes6 × number of sixesAny combination2 3 4 5 6 scores 6
Full HouseTotal of the diceThree of one number and two of another3 3 3 5 5 scores 19
Four of a KindTotal of the four diceAt least four dice showing the same face4 4 4 4 6 scores 16
Little Straight30 points1-2-3-4-51 2 3 4 5 scores 30
Big Straight30 points2-3-4-5-62 3 4 5 6 scores 30
ChoiceSum of the diceAny combination2 3 3 4 6 scores 18
Yacht50 pointsAll five dice showing the same face4 4 4 4 4 scores 50

If the dice do not satisfy the requirements of a category, the score is zero. If, for example, Four Of A Kind is entered in the Yacht category, zero points are scored. A Yacht scores zero if entered in the Full House category.

Open the 01 folder and edit main.py. Run Tests checks it.

For teachers

Yacht

Students solve Exercism's “Yacht” Python exercise in CS Room, with Exercism's own tests.

  • Time: 1 class period
  • Tests: 29, set up for you when you import the lesson
  • Practices: enums