Guest User

Untitled

a guest
Aug 19th, 2014
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import random
  2.  
  3. results = []
  4. for sims in range(1000000):
  5. toss = bool(random.getrandbits(1))
  6. if toss == True:
  7. rooms = 10
  8. else:
  9. rooms = 100
  10. this_room = random.randrange(1, rooms+1)
  11. results.append( (toss, this_room))
  12.  
  13. res_below_10 = [coin for (coin, number) in results if number < 10]
  14. tot = len(res_below_10)
  15. res_True = res_below_10.count(True)
  16. res_False = res_below_10.count(False)
  17. print('{} results in rooms less than 10: {} had 10 rooms ({:.1f}%), {} had 100 rooms {:.1f}%'.format(tot, res_True, res_True/tot*100, res_False, res_False/tot*100))
Advertisement
Add Comment
Please, Sign In to add comment