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实现的json文件读取及中文乱码显示问题解决方法

本文实例讲述了Python实现的json文件读取及中文乱码显示问题解决方法。分享给大家供大家参考,具体如下: city.json文件的内容如下: { "cities": [ {...

Python面向对象之类和对象实例详解

Python面向对象之类和对象实例详解

本文实例讲述了Python面向对象之类和对象。分享给大家供大家参考,具体如下: 类和对象(1) 对象是什么? 对象=属性(静态)+方法(动态); 属性一般是一个个变量;方法是一个个函数;...

python 简单备份文件脚本v1.0的实例

整体思路 将要备份的目录列为一个列表,通过执行系统命令,进行压缩、备份。 这样关键在于构造命令并使用 os.system( )来执行,一开始使用zip 命令始终没有成功,后来发现Wind...

Python入门之modf()方法的使用

 modf()方法返回两个项的元组x的整数小数部分。这两个元组具有相同x符号。则返回一个浮点数的整数部分。 语法 以下是modf()方法的语法: import math...

Python解析网页源代码中的115网盘链接实例

本文实例讲述了python解析网页源代码中的115网盘链接的方法。分享给大家供大家参考。具体方法分析如下: 其中的1.txt,是网页http://bbs.pediy.com/showth...