圆月山庄资源网 Design By www.vgjia.com

Python 石头剪刀布小游戏(三局两胜),供大家参考,具体内容如下

import random
all_choioces = ['石头', '剪刀', '布']
win_list = [['石头', '剪刀'], ['剪刀', '布'], ['布', '石头']]
poeple_on = True
poeple_add = 0
compute_add =0
while poeple_on:
 compute = random.choice(all_choioces)
 put ='''(0)石头(1)剪刀(2)布 请选择:'''
 ind = int(input(put))
 poeple = all_choioces[ind]
 print('你出的:%s,计算机出的是:%s' % (poeple, compute))
 if poeple == compute:
 print('\033[32;1m平局\033[0m')
 elif [poeple, compute] in win_list:
 print('\033[31;1m你赢了\033[0m')
 poeple_add += 1
 if poeple_add == 2:
  poeple_on = False
  print('\033[32;1m游戏结束\033[0m')
 else:
 print('\033[31;1m计算机赢了\033[0m')
 compute_add += 1
 if compute_add == 2:
  poeple_on = False
  print('\033[32;1m游戏结束\033[0m')

第二种简单的格式

import random
all_choioces = ['石头', '剪刀', '布']
win_list = [['石头', '剪刀'], ['剪刀', '布'], ['布', '石头']]
poeple_add = 0
compute_add = 0
while poeple_add < 2 and compute_add < 2 :
 compute = random.choice(all_choioces)
 put ='''(0)石头(1)剪刀(2)布 请选择:'''
 ind = int(input(put))
 poeple = all_choioces[ind]
 print('你出的:%s,计算机出的是:%s' % (poeple, compute))
 if poeple == compute:
 print('\033[32;1m平局\033[0m')
 elif [poeple, compute] in win_list:
 print('\033[31;1m你赢了\033[0m')
 poeple_add += 1
 else:
 print('\033[31;1m计算机赢了\033[0m')
 compute_add += 1

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
python,石头剪刀布,游戏

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com