fork(18) download
  1. import random
  2.  
  3. # pick 2 values, return true if guess was correct
  4. def playGame():
  5. x = random.random()
  6. y = random.random()
  7.  
  8. x_is_bigger = True if x >= 0.5 else False
  9.  
  10. if x_is_bigger and x > y:
  11. return True
  12. elif not x_is_bigger and x < y:
  13. return True
  14.  
  15. num_rounds = 100000
  16. correct = 0
  17. for x in xrange(0, num_rounds):
  18. if playGame():
  19. correct += 1
  20.  
  21. print 'Number of rounds: ' + str(num_rounds)
  22. print 'Number correct: ' + str(correct)
  23. print 'Percent correct: ' + str(correct * 1.0 / num_rounds)
Success #stdin #stdout 0.1s 10024KB
stdin
Standard input is empty
stdout
Number of rounds: 100000
Number correct: 75166
Percent correct: 0.75166