This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/disabled_stuff/coin.py

26 lines
714 B
Python
Raw Permalink Normal View History

2012-09-07 00:50:25 +02:00
import random
2014-02-14 04:36:57 +01:00
from util import hook
2011-11-20 10:23:31 +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:
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.")
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))