Optimized some older code.
This commit is contained in:
parent
99ce2f09a6
commit
b5fbcaaefc
1 changed files with 9 additions and 11 deletions
|
@ -1,14 +1,13 @@
|
|||
# Created by Lukeroge, improved by TheNoodle
|
||||
from util import hook
|
||||
import random
|
||||
from random import getrandbits
|
||||
|
||||
|
||||
# used for tails: x heads: y
|
||||
def flip_simple(count):
|
||||
heads = 0
|
||||
tails = 0
|
||||
for x in range(count):
|
||||
c = random.randint(0, 1)
|
||||
heads, tails = 0, 0
|
||||
for x in xrange(count):
|
||||
c = getrandbits(1)
|
||||
if c == 0:
|
||||
heads += 1
|
||||
else:
|
||||
|
@ -33,13 +32,12 @@ def coin(inp):
|
|||
return "Too many coins! Maximum is 9001."
|
||||
# depending on the count, we use two different methods to get the output
|
||||
if count == 1:
|
||||
flip = random.randint(0, 1)
|
||||
flip = getrandbits(1)
|
||||
if flip == 1:
|
||||
sidename = "heads"
|
||||
return "You flip a coin and get heads."
|
||||
else:
|
||||
sidename = "tails"
|
||||
return "You flip a coin and get " + sidename + "."
|
||||
return "You flip a coin and get tails."
|
||||
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]))
|
||||
return "You flip %i coins and get " \
|
||||
"%i heads and %i tails." % (count, flips[0], flips[1])
|
||||
|
|
Reference in a new issue