################################################
# 使用radom函数,做的双骰子游戏
################################################
import random
def rollNum1():
num1 = random.randrange(1,7)
num2 = random.randrange(1,7)
print('rollNum = ',num1,'+',num2, '=',num1+num2)
return num1+num2
def rollNum2():
num1 = random.randrange(1,7)
num2 = random.randrange(1,7)
print('___rollNum = ',num1,'+',num2, '=',num1+num2)
return num1+num2
print('----------start---------------')
winCounter = 0
loseCounter = 0
for num in range(1,10001,1):
stat = 'continue'
flag = rollNum()
if(7 ==flag or 11 == flag):
winCounter +=1
stat = 'win'
elif(2==flag or 3==flag or 12==flag):
loseCounter +=1
stat = 'lose'
else:
tempf = rollNum2()
while('continue'==stat):
if(7 == tempf):
loseCounter += 1
stat = 'lose'
elif(flag == tempf):
winCounter += 1
stat = 'win'
else:
tempf = rollNum2()
print('win=',winCounter, '\nlose=' ,loseCounter)
|