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实现毫秒级抢单功能

目录: 引言 环境 需求分析&前期准备 淘宝购物流程回顾 秒杀的实现 代码梳理 总结 0 引言 年中购物618大狂欢开始了,各大电商又开始了大力...

Django集成搜索引擎Elasticserach的方法示例

1.背景 当用户在搜索框输入关键字后,我们要为用户提供相关的搜索结果。可以选择使用模糊查询 like 关键字实现,但是 like 关键字的效率极低。查询需要在多个字段中进行,使用 li...

对python中的os.getpid()和os.fork()函数详解

如下所示: import os import sys import time processNmae = 'parent' print "Program executing...

python三引号输出方法

python三引号输出方法

和C语言一样,引号属于特殊功能字符,不能够像普通字符那样直接通过print打印,需要进行一些处理,比如说反斜杠转义等。这里介绍几种打印三引号的方法,希望对需要的朋友有用。 1、第一中方法...

flask中使用SQLAlchemy进行辅助开发的代码

安装方法 1)、apt-ge安装复制代码 代码如下:sudo apt-get install Flask-SQLAlchemy 2)、下载安装包进行安装复制代码 代码如下:# 安装后可直...