from random import *
yes=0
yess=0
N=int(input())
for i in range(N):
c=randint(0,2)###随机车的位置
target=randint(0,2)###开始选择的位置
change=randint(0,1)###随机是否改变,1变
if c==target:###一开始选中了
if change==0:
yes+=1
else:###一开始没有选中
if change==1:##则更换
yess+=1
print(yes/N)###没有更换
print(yess/N)###更换
运行结果:
========== RESTART: C:\Users\LENOVO\Desktop\practice.py =========
10000
0.1618
0.3371
>>>