有四张彩票。一张为中奖彩票。三张为未中奖彩票。去选择一张。然后 主持人打开剩下的三张中的一张为未中奖的彩票。此时给你一次选择的机会。去拿手中的彩票去换剩下的两张。问是否应该 去换彩票。
====特定了条件 主持人打开的未中奖的彩票。
应该去换。
import random
def getTicketArray():
a = random.randint(0,3)
arrList = [0,0,0]
arrList.insert(a,1)
return (arrList,a)
def getChoseTicket(answer):
openT =random.randint(0,3)
if openT ==answer:
return getOpenTicket(answer)
else:
return openT
def getChoseTicket2(answer,answer2):
openT =random.randint(0,3)
if openT==answer:
return getChoseTicket(answer,answer2)
if openT ==answer2:
return getChoseTicket(answer,answer2)
return openT
testNumber = 10000
i=0
total = 0
win=0
j=0
k=0
win2=0
win3=0
while(j<testNumber):
j=j+1
arr = getTicketArray()
ticketList = arr[0]
rightAnswer = arr[1]
answerTicket = random.randint(0,3)
openTicket = getChoseTicket2(answerTicket,rightAnswer)
if(ticketList[openTicket]==1):
print("fail----")
else:
answerTicket = getChoseTicket2(answerTicket,openTicket)
if ticketList[answerTicket]==1:
win2 = win2+1
print("win")
else:
print("fail")
while(k<testNumber):
k=k+1
arr = getTicketArray()
ticketList = arr[0]
rightAnswer = arr[1]
answerTicket = random.randint(0,3)
openTicket = getChoseTicket2(answerTicket,rightAnswer)
if(ticketList[openTicket]==1):
print("fail----")
else:
if ticketList[answerTicket]==1:
win3 = win3+1
print("win")
else:
print("fail")
print(win,win2,win3)
(2515, 3698, 2562)
网友评论