Looking for help. I have three labeled dice1, dice2, and dice3. These variables aall have [1, 2, 3, 4, 5, 6] as their strings. I'm trying to figure out how to write python code for the total possible amount of outcomes that when a number is chosen from each string the sum adds up to 5? Pls help. Sample space would be 216
Looking for help. I have three labeled dice1, dice2, and dice3. These variables aall have [1, 2, 3, 4, 5, 6] as their strings. I'm trying to figure out how to write python code for the total possible amount of outcomes that when a number is chosen from each string the sum adds up to 5? Pls help.
Python Code for finding the number of string add up to 5:
CODE:
outcomes = ['1','2','3','4','5','6']
dice1 = outcomes.copy()
dice2 = outcomes.copy()
dice3 = outcomes.copy()
sum_5 = []
all_outcomes = []
for i in dice1:
for j in dice2:
for k in dice3:
all_outcomes.append(i+j+k)
if int(i)+int(j)+int(k)==5:
sum_5.append(i+j+k)
print(f'Set of all outcomes : {all_outcomes}') # Set of all outcomes
print(f'Set of all outcomes where sum equal to 5: {sum_5}') # Set of all outcome where sum of the string equal to 5
print(f'Total number of outcomes when sum equal to 5:: {len(sum_5)}') # Total number of occurrence where sum add upto 5
Trending now
This is a popular solution!
Step by step
Solved in 2 steps