● 某一天在奇趣多多內(nèi)部發(fā)生了爭(zhēng)執(zhí),佩瑞和喬治決定用隨機(jī)數(shù)來(lái)一場(chǎng)三局兩勝的決斗。
import time
import random ##加載隨機(jī)數(shù)模塊
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) # 取隨機(jī)數(shù)
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【最終結(jié)果:佩瑞贏了!】')
elif qiao_victory > pei_victory:
print('\n【最終結(jié)果:?jiǎn)讨乌A了了!】')
else:
print('\n【最終結(jié)果:平局!】')
到此這篇關(guān)于python基礎(chǔ)之while循環(huán)語(yǔ)句的文章就介紹到這了,更多相關(guān)python的while循環(huán)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!