Python实现简单石头剪刀布游戏


Posted in Python onJanuary 20, 2021

近日在学习Python的一些基础知识,觉得还是很有趣的一个一门语言!就目前的学习的一些知识,编写了一些一个简单的石头剪刀布的游戏。主要是熟悉一些Python的一些控制语句。

import random
while 1:
 s=int(random.randint(1,3))
 print(s)
 print()
 if s==1:
  ind="stone"
 elif s==2:
  ind="scissors"
 elif s==3:
  ind="paper"
 m=input('Please input your option,if you input the end, this game will be end. ')
 blist=['stone','scissors','paper']
 if (m not in blist) and (m!='end'):
  print('your input is wrong and please input the right option again or end the game: ')
 elif (m not in blist) and (m=='end'):
  print('the game is ending now...')
  break
 elif m==ind:
  print('draw')
 elif (m=='stone' and ind=='scissors') or (m=='paper' and ind=='stone') or (m=='scissors' and ind=='paper'):
  print('you win this game')
 elif (m=='stone' and ind=='paper') or (m=='paper' and ind=='scissors') or (m=='scissors' and ind=='stone'):
   print( 'you loss this game')

下面是结果:

Python实现简单石头剪刀布游戏Python实现简单石头剪刀布游戏

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

Python 相关文章推荐
Python脚本实现DNSPod DNS动态解析域名
Feb 14 Python
python通过pil模块获得图片exif信息的方法
Mar 16 Python
python绘图方法实例入门
May 19 Python
Python进程间通信Queue实例解析
Jan 25 Python
python调用百度REST API实现语音识别
Aug 30 Python
pygame游戏之旅 按钮上添加文字的方法
Nov 21 Python
解决Python pandas plot输出图形中显示中文乱码问题
Dec 12 Python
浅谈python中get pass用法
Mar 19 Python
wxPython实现列表增删改查功能
Nov 19 Python
matlab中imadjust函数的作用及应用举例
Feb 27 Python
python 安装库几种方法之cmd,anaconda,pycharm详解
Apr 08 Python
Python使用protobuf序列化和反序列化的实现
May 19 Python
python石头剪刀布小游戏(三局两胜制)
Jan 20 #Python
python 对类的成员函数开启线程的方法
Jan 22 #Python
python实现石头剪刀布小游戏
Jan 20 #Python
对Python3之进程池与回调函数的实例详解
Jan 22 #Python
python多任务及返回值的处理方法
Jan 22 #Python
opencv实现静态手势识别 opencv实现剪刀石头布游戏
Jan 22 #Python
python自动发送测试报告邮件功能的实现
Jan 22 #Python
You might like
自动把纯文本转换成Web页面的php代码
2009/08/27 PHP
第五章 php数组操作
2011/12/30 PHP
CI(CodeIgniter)框架中的增删改查操作
2014/06/10 PHP
typecho插件编写教程(二):写一个新插件
2015/05/28 PHP
php实现的简单美国商品税计算函数
2015/07/13 PHP
PHP中十六进制颜色与RGB颜色值互转的方法
2019/03/18 PHP
js 替换
2008/02/19 Javascript
用javascript获取当页面上鼠标光标位置和触发事件的对象的代码
2009/12/09 Javascript
JavaScript为对象原型prototype添加属性的两种方式
2010/08/01 Javascript
Javascript倒计时页面跳转实例小结
2013/09/11 Javascript
ECMAScript 5中的属性描述符详解
2015/03/02 Javascript
jQuery实现的超酷苹果风格图标滑出菜单效果代码
2015/09/16 Javascript
jQuery表格插件datatables用法汇总
2016/03/29 Javascript
详解Vue2.5+迁移至Typescript指南
2019/08/01 Javascript
webpack + vue 打包生成公共配置文件(域名) 方便动态修改
2019/08/29 Javascript
jQuery实现手风琴效果(蒙版)
2020/01/11 jQuery
在antd4.0中Form使用initialValue操作
2020/11/02 Javascript
[02:53]2018年度DOTA2最佳战队-完美盛典
2018/12/17 DOTA
python 解析html之BeautifulSoup
2009/07/07 Python
跟老齐学Python之玩转字符串(3)
2014/09/14 Python
Python输出9*9乘法表的方法
2015/05/25 Python
Python的装饰器模式与面向切面编程详解
2015/06/21 Python
解析Python中的生成器及其与迭代器的差异
2016/06/20 Python
对python GUI实现完美进度条的示例详解
2018/12/13 Python
Python设计模式之状态模式原理与用法详解
2019/01/15 Python
使用Fabric自动化部署Django项目的实现
2019/09/27 Python
Python3.9新特性详解
2020/10/10 Python
python 制作磁力搜索工具
2021/03/04 Python
英国百年闻名的优质健康产品连锁店:Holland & Barrett
2019/12/19 全球购物
材料采购员岗位职责
2013/12/17 职场文书
租赁协议书范本
2014/04/22 职场文书
干部作风整顿自我剖析材料和整改措施
2014/09/18 职场文书
计算机考试作弊检讨书1000字
2015/01/01 职场文书
公安干警正风肃纪心得体会
2016/01/15 职场文书
SQLServer2019 数据库环境搭建与使用的实现
2021/04/08 SQL Server
django注册用邮箱发送验证码的实现
2021/04/18 Python