我正在尝试找出1个骰子骰中出现奇数的可能性。我知道这是3/6 = 1/2。 公式=可能的结果/总结果= 3个可能的结果/ 6个总结果= 1/2。 同样,如果我将相同的骰子掷出2倍,则概率= 1/2 * 1/2。 一旦生成随机数,我的代码就无法找到可能的总结果。感谢任何指针。
import random
# Determine sample space or total outcomes
N = [1,2,3]
dice_max = 6
outcomes = []
for i in range (len(N)):
elem = N[i]
if elem == 1:
sample_outcomes = elem * dice_max
else:
sample_outcomes = dice_max ** elem
outcomes.append(sample_outcomes)
#print(outcomes)
#print(sample_outcomes)
# Determine if the dice roll is randomly 1,3,5
possible_outcomes = 0
result = random.randint(1, 6)
# Determing possible outcomes
if result == 1 or result ==3 or result ==5:
possible_outcomes +=1
print (possible_outcomes)