Update plugins/coin.py
This commit is contained in:
parent
75b07b2584
commit
8980610aa9
|
@ -1,27 +1,26 @@
|
||||||
from util import hook
|
from util import hook
|
||||||
from random import getrandbits, normalvariate
|
import random
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def coin(inp, me=None):
|
def coin(inp, me=None):
|
||||||
"coin [amount] -- Flips [amount] of coins."
|
"coin [amount] -- Flips [amount] of coins."
|
||||||
|
|
||||||
if inp.isdigit():
|
try:
|
||||||
amount = int(inp)
|
amount = int(inp)
|
||||||
else:
|
except ValueError:
|
||||||
amount = 1
|
return "Invalid input!"
|
||||||
|
|
||||||
if amount > 90001:
|
if amount == 1:
|
||||||
return "Too many coins! Maximum is 90001."
|
|
||||||
elif amount == 1:
|
|
||||||
if getrandbits(1):
|
if getrandbits(1):
|
||||||
me("flips a coin and gets heads.")
|
me("flips a coin and gets heads.")
|
||||||
else:
|
else:
|
||||||
me("flips a coin and gets tails.")
|
me("flips a coin and gets tails.")
|
||||||
|
me("flips a coin and gets %s." % random.choice(["heads", "tails"]))
|
||||||
elif amount == 0:
|
elif amount == 0:
|
||||||
me("makes a coin flipping motion with its hands.")
|
me("makes a coin flipping motion with its hands.")
|
||||||
else:
|
else:
|
||||||
heads = int(normalvariate(.5 * amount, (.75 * amount) ** .5))
|
heads = int(random.normalvariate(.5 * amount, (.75 * amount) ** .5))
|
||||||
tails = amount - heads
|
tails = amount - heads
|
||||||
me("flips %i coins and gets " \
|
me("flips %i coins and gets " \
|
||||||
"%i heads and %i tails." % (amount, heads, tails))
|
"%i heads and %i tails." % (amount, heads, tails))
|
||||||
|
|
Reference in a new issue