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

yipeiwu_com6年前Python基础

近日在学习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中的文件管理 文件管理是很多应用程序的基本功能和重要组成部分。Python可以使文件管理极其...

PyCharm代码提示忽略大小写设置方法

PyCharm代码提示忽略大小写设置方法

如图: 具体见上图! 以上这篇PyCharm代码提示忽略大小写设置方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。...

linux查找当前python解释器的位置方法

先进入python 输入 import sys sys.executable 即可! 以上这篇linux查找当前python解释器的位置方法就是小编分享给大家的全部内容了,希望能给...

python3.6.3+opencv3.3.0实现动态人脸捕获

python3.6.3+opencv3.3.0实现动态人脸捕获

本文实例为大家分享了python实现动态人脸捕获的具体代码,供大家参考,具体内容如下 步骤 载入cv2 捕获摄像头 获取第一帧图像 定义人脸识别信息 开始循环...

Python3中简单的文件操作及两个简单小实例分享

前言 首先介绍一下什么叫做相对路径和绝对路径,我们程序狗家族想必都是懂这个的,但是难免会有童鞋忘记。所以码出来供大家快速回忆一下。 相对路径 相对路径是相对于文件当前的工作路径而言的 绝...