2012-09-07 00:50:25 +02:00
|
|
|
import random
|
2011-12-02 14:42:36 +01:00
|
|
|
|
2014-02-14 04:36:57 +01:00
|
|
|
from util import hook
|
|
|
|
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2011-12-01 17:13:08 +01:00
|
|
|
@hook.command(autohelp=False)
|
2013-10-01 04:41:54 +02:00
|
|
|
def coin(inp, action=None):
|
2013-09-04 12:30:04 +02:00
|
|
|
"""coin [amount] -- Flips [amount] of coins."""
|
2012-08-20 22:11:48 +02:00
|
|
|
|
2012-09-12 23:08:24 +02:00
|
|
|
if inp:
|
|
|
|
try:
|
|
|
|
amount = int(inp)
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
return "Invalid input!"
|
|
|
|
else:
|
2012-09-12 23:05:03 +02:00
|
|
|
amount = 1
|
2012-02-17 01:46:09 +01:00
|
|
|
|
2012-09-07 00:50:25 +02:00
|
|
|
if amount == 1:
|
2013-10-01 04:41:54 +02:00
|
|
|
action("flips a coin and gets {}.".format(random.choice(["heads", "tails"])))
|
2012-08-20 22:11:48 +02:00
|
|
|
elif amount == 0:
|
2013-10-01 04:41:54 +02:00
|
|
|
action("makes a coin flipping motion with its hands.")
|
2011-12-01 17:13:08 +01:00
|
|
|
else:
|
2012-09-07 00:50:25 +02:00
|
|
|
heads = int(random.normalvariate(.5 * amount, (.75 * amount) ** .5))
|
2012-09-06 06:52:32 +02:00
|
|
|
tails = amount - heads
|
2013-10-01 04:41:54 +02:00
|
|
|
action("flips {} coins and gets {} heads and {} tails.".format(amount, heads, tails))
|