python石头剪刀布小游戏(三局两胜制)

作者:A_Gorilla 时间:2021-07-24 00:06:30 

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

来源:https://blog.csdn.net/A_Gorilla/article/details/81709825

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

猜你喜欢

  • 更改localhost为其他名字的方法

    2023-11-23 08:07:52
  • python:按行读入,排序然后输出的方法

    2021-09-15 06:13:58
  • PyQt5使用mimeData实现拖拽事件教程示例解析下

    2021-02-15 11:09:03
  • python切片作为占位符使用实例讲解

    2023-10-13 09:26:50
  • Oracle数据库的十种重新启动步骤

    2012-07-21 14:58:25
  • Python统计词频并绘制图片(附完整代码)

    2022-01-01 09:28:24
  • python连接字符串的方法小结

    2023-12-29 16:24:49
  • 微信小程序request请求后台接口php的实例详解

    2023-11-11 14:24:04
  • Python数据存储之XML文档和字典的互转

    2023-02-12 08:56:11
  • python日期相关操作实例小结

    2021-07-14 18:39:13
  • swfobject2.1居中问题

    2008-12-15 17:18:00
  • 教你使用Python的pygame模块实现拼图游戏

    2022-06-28 03:20:20
  • PHP程序员最常犯的11个MySQL错误

    2012-01-05 19:13:02
  • Python入门教程1. 基本运算【四则运算、变量、math模块等】 <font color=red>原创</font>

    2023-12-21 19:44:16
  • Python学习之加密模块使用详解

    2022-06-01 03:58:03
  • Python使用Selenium实现淘宝抢单的流程分析

    2022-01-31 04:04:18
  • selenium+python自动化测试之页面元素定位

    2021-09-30 18:08:55
  • 基于php解决json_encode中文UNICODE转码问题

    2023-07-02 20:51:22
  • asp中提取HTML中图片的SRC路径

    2008-10-24 08:42:00
  • python实现黄金分割法的示例代码

    2022-08-27 19:41:17
  • asp之家 网络编程 m.aspxhome.com