jweinst1

6/29/2015 - 8:08 AM

HogProject.py

```
import random
def hogdice_six_sided(dice):
dices = []
while len(dices) < dice:
dices.append(random.randrange(1,7))
if 1 in dices:
return 1
else:
return sum(dices)
def hogdice_four_sided(dice):
dices = []
while len(dices) < dice:
dices.append(random.randrange(1,5))
if 1 in dices:
return 1
else:
return sum(dices)
def average_number_of_rolls(dice):
turn_count, score = 0, 0
while score < 100:
score += hogdice_six_sided(dice)
turn_count += 1
return turn_count
def average_of_total_games(dice, number):
list_of_turns = []
while len(list_of_turns) < number:
list_of_turns.append(average_number_of_rolls(dice))
return (sum(list_of_turns)/number)
def total_outcome_dictionary(number):
return {x:average_of_total_games(x, number) for x in range(1, 11)}
""">>> average_of_total_games(3, 10)
12
>>> average_of_total_games(3, 100)
14
>>> average_of_total_games(3, 1000)
14
>>> average_of_total_games(3, 10000)
14
>>> average_of_total_games(3, 10000)
14
six_sided_dice
>>> total_outcome_dictionary(10)
{1: 28, 2: 18, 3: 14, 4: 14, 5: 14, 6: 12, 7: 15, 8: 14, 9: 18, 10: 16}
>>> total_outcome_dictionary(100)
{1: 29, 2: 17, 3: 14, 4: 13, 5: 12, 6: 11, 7: 13, 8: 13, 9: 15, 10: 15}
>>> total_outcome_dictionary(1000)
{1: 29, 2: 17, 3: 14, 4: 13, 5: 12, 6: 12, 7: 13, 8: 13, 9: 14, 10: 16}
>>> total_outcome_dictionary(10000)
{1: 29, 2: 17, 3: 14, 4: 13, 5: 12, 6: 12, 7: 13, 8: 13, 9: 15, 10: 16}
four sided_dice
>>> total_outcome_dictionary(100)
{1: 40, 2: 26, 3: 23, 4: 23, 5: 25, 6: 26, 7: 30, 8: 34, 9: 36, 10: 43}
>>> total_outcome_dictionary(1000)
{1: 40, 2: 26, 3: 23, 4: 23, 5: 24, 6: 26, 7: 29, 8: 33, 9: 36, 10: 41}
>>> total_outcome_dictionary(1000)
{1: 40, 2: 26, 3: 23, 4: 23, 5: 24, 6: 26, 7: 29, 8: 33, 9: 36, 10: 41}
>>> total_outcome_dictionary(10000)
{1: 40, 2: 26, 3: 23, 4: 23, 5: 24, 6: 26, 7: 29, 8: 32, 9: 36, 10: 41}
"""
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
def probability_of_swap():
return [x + y for x in numbers for y in numbers]
def digitsinonehundred():
return [x+y for x in numbers for y in numbers]
def all_possible_pairs():
return [(x,y) for x in digitsinonehundred() for y in digitsinonehundred()]
def swap_pairs():
return [(x,y) for x in probability_of_swap() for y in probability_of_swap() if x == y[::-1] and x != y]
```