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/plugins/coin.py
2012-02-28 21:47:11 -08:00

46 lines
1.2 KiB
Python
Executable file

# Created by Lukeroge, improved by TheNoodle
from util import hook
import random
# used for tails: x heads: y
def flip_simple(count):
heads = 0
tails = 0
for x in range(count):
c = random.randint(0, 1)
if c == 0:
heads += 1
else:
tails += 1
return [heads, tails]
@hook.command(autohelp=False)
def coin(inp):
".coin [amount] -- Flips [amount] of coins."
# checking for valid input. if valid input [count=inp],
# if invalid [return error], if no input [count=1]
if inp.isdigit():
count = int(inp)
else:
if inp:
return "Invalid input."
else:
count = 1
if count > 200:
return "Too many coins! Maximum is 200."
# depending on the count, we use two different methods to get the output
if count == 1:
flip = random.randint(0, 1)
if flip == 1:
sidename = "heads"
else:
sidename = "tails"
return "You flip a coin and get " + sidename + "."
else:
flips = flip_simple(count)
return "You flip %s coins and get "\
"%s heads and %s tails." % (str(count), str(flips[0]), str(flips[1]))