Created
March 6, 2014 20:41
-
-
Save redspider/9399212 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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