Skip to content

Instantly share code, notes, and snippets.

@redspider
Created March 6, 2014 20:41
Show Gist options
  • Save redspider/9399212 to your computer and use it in GitHub Desktop.
Save redspider/9399212 to your computer and use it in GitHub Desktop.
"""
If you choose an answer to this question at random,
what is the chance you will be correct?
A) 25%
B) 50%
C) 60%
D) 25%
"""
import random
ANSWERS = [25,50,60,25]
def guess():
answer = random.choice(ANSWERS)
guess = random.choice(ANSWERS)
if guess == answer:
return True
return False
percentage = 0
# Keep trying until we get a random distribution that finds the answer we want.
while not percentage in ANSWERS:
guesses = 100
correct = 0
for i in range(0,guesses):
if guess():
correct +=1
percentage = int(100.0/guesses*correct)
print "VICTORY with %d" % percentage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment