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的Scrapy框架编写web爬虫的简单示例
Apr 17 Python
python获得一个月有多少天的方法
Jun 04 Python
利用Python爬取可用的代理IP
Aug 18 Python
python 寻找优化使成本函数最小的最优解的方法
Dec 28 Python
python 处理dataframe中的时间字段方法
Apr 10 Python
Flask框架信号用法实例分析
Jul 24 Python
python 格式化输出百分号的方法
Jan 20 Python
对python中基于tcp协议的通信(数据传输)实例讲解
Jul 22 Python
python接口调用已训练好的caffe模型测试分类方法
Aug 26 Python
如何将你的应用迁移到Python3的三个步骤
Dec 22 Python
关于Tensorflow 模型持久化详解
Feb 12 Python
python基础之类属性和实例属性
Oct 24 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反转字符串函数strrev()函数的用法
2012/02/04 PHP
深入apache配置文件httpd.conf的部分参数说明
2013/06/28 PHP
PHP简单实现冒泡排序的方法
2016/12/26 PHP
一个js实现的所谓的滑动门
2007/05/23 Javascript
js 数值项目的格式化函数代码
2010/05/14 Javascript
JS滚轮事件onmousewheel使用介绍
2013/11/01 Javascript
点击页面其它地方隐藏该div的两种思路
2013/11/18 Javascript
谈一谈jQuery核心架构设计
2016/03/28 Javascript
使用jQuery Ajax 请求webservice来实现更简练的Ajax
2016/08/04 Javascript
angular基于路由控制ui-router实现系统权限控制
2016/09/27 Javascript
js 定位到某个锚点的方法
2016/11/19 Javascript
jquery中封装函数传递当前元素的方法示例
2017/05/05 jQuery
Typescript 中的 interface 和 type 到底有什么区别详解
2019/06/18 Javascript
解决layer.msg 不居中 ifram中的问题
2019/09/05 Javascript
Vue 技巧之控制父类的 slot
2020/02/24 Javascript
vue 避免变量赋值后双向绑定的操作
2020/11/07 Javascript
使用SAE部署Python运行环境的教程
2015/05/05 Python
Python Matplotlib库入门指南
2015/05/18 Python
Python爬虫DNS解析缓存方法实例分析
2017/06/02 Python
解决Django migrate No changes detected 不能创建表的问题
2018/05/27 Python
python实现简单多人聊天室
2018/12/11 Python
python制作英语翻译小工具代码实例
2019/09/09 Python
python 两个数据库postgresql对比
2019/10/21 Python
使用Tensorflow实现可视化中间层和卷积层
2020/01/24 Python
Python实现删除某列中含有空值的行的示例代码
2020/07/20 Python
详解matplotlib绘图样式(style)初探
2021/02/03 Python
eDreams德国:南欧领先的在线旅游公司
2020/12/07 全球购物
武汉东之林科技有限公司机试
2013/09/17 面试题
列车长先进事迹材料
2014/01/25 职场文书
幼儿老师求职信
2014/06/30 职场文书
2015秋学期开学寄语
2015/05/28 职场文书
公司劳动纪律管理制度
2015/08/04 职场文书
员工旷工检讨书
2015/08/15 职场文书
2016年教师节特级教师获奖感言
2015/12/09 职场文书
vue ant design 封装弹窗表单的使用
2022/06/01 Vue.js
Flink 侧流输出源码示例解析
2022/09/23 Servers