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写的图片蜘蛛人代码
Aug 27 Python
python开发之thread线程基础实例入门
Nov 11 Python
python基础知识小结之集合
Nov 25 Python
浅谈Python基础之I/O模型
May 11 Python
使用Python进行目录的对比方法
Nov 01 Python
对python借助百度云API对评论进行观点抽取的方法详解
Feb 21 Python
Python中捕获键盘的方式详解
Mar 28 Python
PyQt5 QTable插入图片并动态更新的实例
Jun 18 Python
用python3 urllib破解有道翻译反爬虫机制详解
Aug 14 Python
利用rest framework搭建Django API过程解析
Aug 31 Python
深入理解Python 多线程
Jun 16 Python
Python+Selenium随机生成手机验证码并检查页面上是否弹出重复手机号码提示框
Sep 21 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
聊天室php&mysql(四)
2006/10/09 PHP
php读取csv数据保存到数组的方法
2015/01/03 PHP
javascript模仿msgbox提示效果代码
2008/06/10 Javascript
jQuery实现鼠标经过提示信息的地图热点效果
2015/04/26 Javascript
20分钟打造属于你的Bootstrap站点
2016/07/27 Javascript
解决Layui选择全部,换页checkbox复选框重新勾选的问题方法
2018/08/14 Javascript
jQuery实现的自定义轮播图功能详解
2018/12/28 jQuery
微信小程序实现工作时间段选择
2019/02/15 Javascript
Vue项目中配置pug解析支持
2019/05/10 Javascript
《javascript设计模式》学习笔记七:Javascript面向对象程序设计组合模式详解
2020/04/08 Javascript
vue.js实现h5机器人聊天(测试版)
2020/07/16 Javascript
解决新建一个vue项目过程中遇到的问题
2020/10/22 Javascript
[01:35]2014DOTA2西雅图邀请赛 专访狐狸妈青春献给刀塔
2014/07/08 DOTA
[56:45]DOTA2上海特级锦标赛D组小组赛#1 EG VS COL第一局
2016/02/28 DOTA
Python实现端口复用实例代码
2014/07/03 Python
python操作字典类型的常用方法(推荐)
2016/05/16 Python
Python 爬虫之超链接 url中含有中文出错及解决办法
2017/08/03 Python
轻松实现TensorFlow微信跳一跳的AI
2018/01/05 Python
python实现壁纸批量下载代码实例
2018/01/25 Python
python2 与 pyhton3的输入语句写法小结
2018/09/10 Python
Python文件监听工具pyinotify与watchdog实例
2018/10/15 Python
Pandas+Matplotlib 箱式图异常值分析示例
2019/12/09 Python
Python使用gluon/mxnet模块实现的mnist手写数字识别功能完整示例
2019/12/18 Python
如何通过python实现全排列
2020/02/11 Python
Jupyter notebook运行Spark+Scala教程
2020/04/10 Python
python可以用哪些数据库
2020/06/22 Python
PyCharm安装PyQt5及其工具(Qt Designer、PyUIC、PyRcc)的步骤详解
2020/11/02 Python
解决Pymongo insert时会自动添加_id的问题
2020/12/05 Python
澳洲在线厨具商店:Kitchen Style
2018/05/05 全球购物
函数指针的定义是什么
2016/08/14 面试题
鲁迅故里导游词
2015/02/05 职场文书
新郎接新娘保证书
2015/05/08 职场文书
办公用品质量保证书
2015/05/11 职场文书
鲁滨孙漂流记读书笔记
2015/06/30 职场文书
Python中第三方库Faker的使用详解
2022/04/02 Python
LyScript实现绕过反调试保护的示例详解
2022/08/14 Python