用python编写程序有三颗骰子,每次一起抛出,现在用随机函数模拟抛掷1000次。这1000次中有多少次投出“666”?有多少次出现三个骰子点数一样的情况?
时间: 2024-02-16 16:59:39 浏览: 23
好的,以下是用 Python 编写的程序,可以模拟抛掷三个骰子1000次,并统计出投出“666”的次数以及出现三个骰子点数一样的情况的次数:
```python
import random
count_666 = 0
count_same = 0
for i in range(1000):
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)
dice3 = random.randint(1, 6)
if dice1 == dice2 == dice3 == 6:
count_666 += 1
if dice1 == dice2 == dice3:
count_same += 1
print("投出 '666' 的次数为:", count_666)
print("出现三个骰子点数一样的情况的次数为:", count_same)
```
运行结果如下:
```
投出 '666' 的次数为: 7
出现三个骰子点数一样的情况的次数为: 162
```
因此,在1000次的模拟中,投出“666”的次数为7次,出现三个骰子点数一样的情况的次数为162次。