Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- results = []
- for sims in range(1000000):
- toss = bool(random.getrandbits(1))
- if toss == True:
- rooms = 10
- else:
- rooms = 100
- this_room = random.randrange(1, rooms+1)
- results.append( (toss, this_room))
- res_below_10 = [coin for (coin, number) in results if number < 10]
- tot = len(res_below_10)
- res_True = res_below_10.count(True)
- res_False = res_below_10.count(False)
- 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