Skip to main content

challenge_421_dice_game.py


"""
421 or four-twenty-one is a French dice game.
Write a program to play that game.
The rules are as follow:
You roll three dices.
- If you get a 4 a 2 and a 1, the computer says 'Hooray, 421!'
- If you get three of a kind, the computer says 'great, I got triple x'
  with x the number you rolled
- If you get two of a kind, the computer says 'not too bad, double x'
- Otherwise, the computer says 'Too bad!'
Author: L J Gregoire
"""
from random import randint
# roll dices
dices=[randint(1,6),randint(1,6),randint(1,6)]
print dices
# sort the dices from lowest to highest
# so we can easily check we have 421
# or two identical dices
dices.sort()
print 'sorted', dices
# check the results
if (dices[0]==1 and dices[1]==2 and dices[3]==4):
    print 'Hooray, 421 !'
elif (dices[0]==dices[1]==dices[2]):
    print 'great, I got triple',dices[0]
elif (dices[0]==dices[1] or dices[1]==dices[2]):
    print 'not too bad, double',dices[1]
else:
    print 'Too bad'
###