Python 学习之路
这个是我学python以来,写的的第一个小游戏,写的不好
题目:石头剪刀布
主要有两个难度
在普通模式,电脑是随机出
在噩梦下,就是不管你出什么,电脑都会赢你,牛逼吧
1 import random 2 com=('剪刀','石头','布') 3 compare=(('剪刀','布'),('石头','剪刀'),('布','石头')) 4 bifen={'玩家':0,'电脑':0,'平局':0} 5 print('--------猜拳小游戏-----------(输入F退出游戏)')
1 count=0#比赛局数计数 2 while True:#选择难度 3 print(''' 4 1.普通人机 5 2.噩梦人机 6 ''') 7 judge=input('选择模式\t>>>>>') 8 if judge=='1' or judge=='2': 9 break 10 else: 11 print('暂无该模式,重新选择,')
1 while True: 2 count+=1 3 print('---------第 %s 局---------'%count) 4 people=input('玩家:') 5 if judge =='1': 6 computer=random.choice(com) 7 else: 8 for i in compare: 9 if people==i[1]: 10 computer=i[0] 11 print('电脑:', computer) 12 if people==computer: 13 print('平局,在来一局') 14 bifen['平局']+=1 15 elif (people,computer)in compare: 16 print('胜利!') 17 bifen['玩家'] += 1 18 elif (computer,people) in compare: 19 print('失败!') 20 bifen['电脑'] += 1 21 elif people=='F': 22 print('--------比赛结果---------') 23 print(bifen) 24 if bifen['玩家']>bifen['电脑']: 25 print('大吉大利,晚上吃鸡') 26 elif bifen['玩家']==bifen['电脑']: 27 print('你居然和人机有来有回,不相上下!') 28 else: 29 print('牛逼啊,还输给个人机') 30 break 31 else: 32 print('你连规则都不知道,还玩个毛线啊')
好吧,就这样