Dice game¶
We want to play a variant of the dice game called craps where there is a starting two dice roll and the following rules:
If dice add up to 7 or 11 the player wins.
If dice add up to 2, 3 or 12, the player loses.
With any other combination, the player keeps playing.
Write the function dice2() that takes two values
corresponding to the result of a two dice roll, and returns an
integer: 0 if the player keeps playing, 1 if the player wins and 2 if
the player loses. The function must check if the dice values are right
(they are between 1 and 6) and must return -1 if they aren’t right.
Save this function into a file named dice_game.py. Examples:
>>> dice2(6, 5) 1 >>> dice2(1, 2) 2 >>> dice2(4, 4) 0 >>> dice2(5, -3) -1Note
More tests are provided in the
dice_game.txt
Solutions
A solution of this function is provided in the dice_game.py