From cd9e35ed33f0f884621188410c5cfcb0178217a1 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 2 Dec 2011 05:13:08 +1300 Subject: [PATCH] coin.py is now a nest og if statements. Huzzah --- plugins/coin.py | 70 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/plugins/coin.py b/plugins/coin.py index 8754bf3..d9929fe 100644 --- a/plugins/coin.py +++ b/plugins/coin.py @@ -2,38 +2,62 @@ from util import hook import random -@hook.command(autohelp=False) -def coin(inp): - ".coin [amount] -- flips some coins and shares the result." - - if inp.isdigit(): - count = int(inp) - else: - count = 1 - - if count > 10: - return "Maximum amount of coins is ten." - - if count > 1: - coin = "coins" - else: - coin = "coin" - - msg = "You flip " + str(count) + " " + coin + " and get the following results:" +## NOTES: +## Need to make a function to return a number of flips +# this produces a string full of comma seperated coin flips - should output this as a list +def flip_list(count): + out = "" for i in range(count): flip = random.randint(0,1) if flip == 1: if i == 0: - msg += " Heads" + out += "Heads" else: - msg += ", Heads" + out += ", Heads" else: if i == 0: - msg += " Tails" + out += "Tails" else: - msg += ", Tails" - + out += ", Tails" + return out +# this doesn't work (yet) +def flip_simple(count): + out = "" + heads = 0 + tails = 0 + for i in range(count): + flip = random.randint(0,1) + if flip == 1: + heads = heads + 1 + else: + tails = tails + 1 return msg +@hook.command(autohelp=False) +def coin(inp): + ".coin [amount] -- flips some coins and shares the result." + + # 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 + + # depending on the count, we use three different methods to get the output + if count <= 10 and count > 1: + msg = "You flip " + str(count) + " coins and get the following results: " + flip_list(count) + return msg + elif count == 1: + flip = random.randint(0,1) + if flip == 1: + return "You flip a coin and get heads." + else: + return "You flip a coin and get tails." + else: + return "Amounts over ten are not yet implemented" +