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实现k均值算法示例(k均值聚类算法)
Mar 16 Python
在Python的Django框架中使用通用视图的方法
Jul 21 Python
Python中创建字典的几种方法总结(推荐)
Apr 27 Python
Python中装饰器兼容加括号和不加括号的写法详解
Jul 05 Python
Python实现针对给定单链表删除指定节点的方法
Apr 12 Python
python 执行shell命令并将结果保存的实例
May 11 Python
python构建基础的爬虫教学
Dec 23 Python
在Python 中同一个类两个函数间变量的调用方法
Jan 31 Python
wxPython实现分隔窗口
Nov 19 Python
Python利用逻辑回归模型解决MNIST手写数字识别问题详解
Jan 14 Python
Ubuntu18.04安装 PyCharm并使用 Anaconda 管理的Python环境
Apr 08 Python
使用keras2.0 将Merge层改为函数式
May 23 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
「OVERLORD」动画重要删减!雅儿贝德的背叛?至尊猎杀队结成
2020/04/09 日漫
PHP Global变量定义当前页面的全局变量实现探讨
2013/06/05 PHP
PHP程序员简单的开展服务治理架构操作详解(一)
2020/05/14 PHP
简明json介绍
2008/09/28 Javascript
SharePoint 客户端对象模型 (一) ECMA Script
2011/05/22 Javascript
使用jquery实现select添加实现后台权限添加的效果
2011/05/28 Javascript
jQuery实现下拉框左右移动(全部移动,已选移动)
2016/04/15 Javascript
基于node实现websocket协议
2016/04/25 Javascript
15个值得开发人员关注的jQuery开发技巧和心得总结【经典收藏】
2016/05/25 Javascript
设置jQueryUI DatePicker默认语言为中文
2016/06/04 Javascript
jQuery文字提示与图片提示效果实现方法
2016/07/04 Javascript
jQuery如何封装输入框插件
2016/08/19 Javascript
jquery实现用户登陆界面(示例讲解)
2017/09/06 jQuery
使用rollup打包JS的方法步骤
2018/12/05 Javascript
快速了解Node中的Stream流是什么
2019/02/13 Javascript
python基础教程之基本内置数据类型介绍
2014/02/20 Python
举例讲解Python中装饰器的用法
2015/04/27 Python
python实现感知器算法详解
2017/12/19 Python
Python编程求质数实例代码
2018/01/31 Python
浅谈numpy生成数组的零值问题
2018/11/12 Python
python并发和异步编程实例
2018/11/15 Python
python中的单引号双引号区别知识点总结
2019/06/23 Python
对于Python深浅拷贝的理解
2019/07/29 Python
Python数据可视化:泊松分布详解
2019/12/07 Python
django 将自带的数据库sqlite3改成mysql实例
2020/07/09 Python
CSS3弹性布局内容对齐(justify-content)属性使用详解
2017/07/31 HTML / CSS
美国最大婚纱连锁店运营商:David’s Bridal
2019/03/12 全球购物
英国最大的割草机购买网站:Just Lawnmowers
2019/11/02 全球购物
专业幼师实习生自我鉴定范文
2013/12/08 职场文书
数学检讨书1000字
2014/02/24 职场文书
不服从上级领导安排的检讨书
2014/09/14 职场文书
大二学生自我检讨书
2014/10/23 职场文书
高中生综合素质自我评价
2015/03/06 职场文书
入党积极分子半年考察意见
2015/06/02 职场文书
民间借贷纠纷起诉书
2015/08/03 职场文书
《多彩的民间艺术》教学反思
2016/02/16 职场文书