Write a simulation of the rolling of 2 six-sided dice. Your program should have a function Roll() that returns the sum of rolling your dice. You may assume that each of the six sides is equally likely to be rolled (that is, the dice are "fair"). Run your simulation 1000 times and report the frequency that each sum occurred.
I have this so far but my program wont seem to add up the sums. I may be completely wrong. Any help please. I think my main issue is in my printing statement. I need the output to print how many times does the sum of 2 shows, sum of 3, sum of 4, etc till 12.
def Roll():
for i in range(1000):
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
dice1= float(0)
dice2= float(0)
dice1 = random.randint(1,6)
if dice1 == 1:
one = one + 1
count= 1
return count
elif dice1 == 2:
two = two + 1
count= 1
return count
elif dice1 == 3:
three = three + 1
count= 1
return count
elif dice1 == 4:
four = four + 1
count= 1
return count
elif dice1 == 5:
five = five + 1
count= 1
return count
else:
six = six + 1
count= 1
return count
dice2 = random.randint(1,6)
if dice2 == 1:
one = one + 1
elif dice2 == 2:
two = two + 1
elif dice2 == 3:
three = three + 1
elif dice2 == 4:
four = four + 1
elif dice2 == 5:
five = five + 1
else:
six = six + 1
total = one + two + three + four + five + six
print("2", dice1 + dice2)
print("3", dice1 + dice2)
print("4", dice1 + dice2)
print("5", dice1 + dice2)
print("6", dice1 + dice2)
print("7", dice1 + dice2)
print("8", dice1 + dice2)
print("9", dice1 + dice2)
print("10", dice1 + dice2)
print("11", dice1 + dice2)
print("12", dice1 + dice2)
I already answered a friend of yours with the same assignment:
You can take out the parts which are useful to you. This should also cover the follow-up questions like: "How do I print it neatly" and "How do I draw a histogram".
Example: