import time
import random ##加载随机数模块
pei_victory = 0
qiao_victory = 0
dict1 = {1:'剪刀',2:'石头',3:'布'}
for i in range(1,4):
time.sleep(2)
print(' \n——————第 %s 局——————' % i)
peiqi_rand = random.randint(1, 3) # 取随机数
qiaoz_rand = random.randint(1, 3)
print(dict1[peiqi_rand])
print(dict1[qiaoz_rand])
if peiqi_rand ==1:
if qiaoz_rand == 1:
print("平局")
elif qiaoz_rand == 2 :
print ("本次乔治获胜")
qiao_victory +=1
else :
print("本次佩瑞获胜")
pei_victory += 1
elif peiqi_rand ==2:
if qiaoz_rand == 2:
print= ("平局")
elif qiaoz_rand == 3:
print("本次乔治获胜")
qiao_victory +=1
else :
print("本次佩瑞获胜")
pei_victory += 1
else :
if qiaoz_rand == 3:
print ("平局")
elif qiaoz_rand == 1:
print("本次乔治获胜")
qiao_victory +=1
else :
print("本次佩瑞获胜")
pei_victory += 1
if pei_victory > qiao_victory :
time.sleep(1)
print('\n【最终结果:佩瑞赢了!】')
elif qiao_victory > pei_victory:
print('\n【最终结果:乔治赢了了!】')
else:
print('\n【最终结果:平局!】')
到此这篇关于python基础之while循环语句的文章就介绍到这了,更多相关python的while循环内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!