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

64 lines
1.7 KiB
Python
Raw Normal View History

2011-11-20 10:23:31 +01:00
# # Lukeroge
from util import hook
import random
## NOTES:
## Need to make a function to return a number of flips
2011-12-01 15:24:11 +01:00
# this produces a string full of comma seperated coin flips - should output this as a list
def flip_list(count):
out = ""
2011-12-01 15:24:11 +01:00
for i in range(count):
flip = random.randint(0,1)
if flip == 1:
if i == 0:
out += "Heads"
2011-12-01 15:24:11 +01:00
else:
out += ", Heads"
2011-12-01 15:24:11 +01:00
else:
if i == 0:
out += "Tails"
2011-12-01 15:24:11 +01:00
else:
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
2011-12-01 15:24:11 +01:00
return msg
2011-11-20 10:23:31 +01:00
@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"