python基础之while循环语句的使用
● 某一天在奇趣多多内部发生了争执,佩瑞和乔治决定用随机数来一场三局两胜的决斗。
● 结果出来了,乔治表示很不服…
import timeimport random ##加载随机数模块pei_victory = 0qiao_victory = 0dict1 = {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 += 1if pei_victory > qiao_victory : time.sleep(1) print(’n【最终结果:佩瑞赢了!】’)elif qiao_victory > pei_victory: print(’n【最终结果:乔治赢了了!】’)else: print(’n【最终结果:平局!】’)
到此这篇关于python基础之while循环语句的文章就介绍到这了,更多相关python的while循环内容请搜索好吧啦网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好吧啦网!
相关文章: