2012-02-20 04:34:17 +01:00
|
|
|
# Created by Lukeroge, improved by TheNoodle
|
2011-11-20 10:23:31 +01:00
|
|
|
from util import hook
|
|
|
|
import random
|
|
|
|
|
2012-02-29 06:47:11 +01:00
|
|
|
|
2012-02-20 04:34:17 +01:00
|
|
|
# used for tails: x heads: y
|
2011-12-01 17:13:08 +01:00
|
|
|
def flip_simple(count):
|
|
|
|
heads = 0
|
|
|
|
tails = 0
|
2011-12-02 14:42:36 +01:00
|
|
|
for x in range(count):
|
2012-02-29 06:47:11 +01:00
|
|
|
c = random.randint(0, 1)
|
2011-12-02 14:42:36 +01:00
|
|
|
if c == 0:
|
|
|
|
heads += 1
|
2011-12-01 17:13:08 +01:00
|
|
|
else:
|
2011-12-02 14:42:36 +01:00
|
|
|
tails += 1
|
2012-02-29 06:47:11 +01:00
|
|
|
return [heads, tails]
|
2011-12-02 14:42:36 +01:00
|
|
|
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2011-12-01 17:13:08 +01:00
|
|
|
@hook.command(autohelp=False)
|
|
|
|
def coin(inp):
|
2012-02-28 03:03:43 +01:00
|
|
|
".coin [amount] -- Flips [amount] of coins."
|
2012-02-29 06:47:11 +01:00
|
|
|
# checking for valid input. if valid input [count=inp],
|
|
|
|
# if invalid [return error], if no input [count=1]
|
2011-12-01 17:13:08 +01:00
|
|
|
if inp.isdigit():
|
|
|
|
count = int(inp)
|
|
|
|
else:
|
|
|
|
if inp:
|
2012-02-17 01:46:09 +01:00
|
|
|
return "Invalid input."
|
2011-12-01 17:13:08 +01:00
|
|
|
else:
|
|
|
|
count = 1
|
2012-02-17 01:46:09 +01:00
|
|
|
|
|
|
|
if count > 200:
|
|
|
|
return "Too many coins! Maximum is 200."
|
2011-12-02 14:42:36 +01:00
|
|
|
# depending on the count, we use two different methods to get the output
|
|
|
|
if count == 1:
|
2012-02-29 06:47:11 +01:00
|
|
|
flip = random.randint(0, 1)
|
2011-12-01 17:13:08 +01:00
|
|
|
if flip == 1:
|
2011-12-02 14:42:36 +01:00
|
|
|
sidename = "heads"
|
2011-12-01 17:13:08 +01:00
|
|
|
else:
|
2011-12-02 14:42:36 +01:00
|
|
|
sidename = "tails"
|
2012-02-29 06:47:11 +01:00
|
|
|
return "You flip a coin and get " + sidename + "."
|
2011-12-01 17:13:08 +01:00
|
|
|
else:
|
2011-12-02 14:42:36 +01:00
|
|
|
flips = flip_simple(count)
|
2012-03-12 12:40:37 +01:00
|
|
|
return "You flip %s coins and get " \
|
2012-02-29 06:47:11 +01:00
|
|
|
"%s heads and %s tails." % (str(count), str(flips[0]), str(flips[1]))
|