This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/disabled_stuff/coin.py

26 lines
714 B
Python
Raw Normal View History

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