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

yipeiwu_com5年前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实现上下班抢个顺风单脚本

一 程序预览 本程序已经写了多年, 很久没用, 不过刚运行了下竟然还可以成功运行. 先来张运行结果图. 二 最近的滴滴APP已经可以支持设置自动抢单功能, 这个小程序就没有那么大意义了...

Python numpy线性代数用法实例解析

Python numpy线性代数用法实例解析

这篇文章主要介绍了Python numpy线性代数用法实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 numpy中线性代数用法...

Python常用特殊方法实例总结

本文实例讲述了Python常用特殊方法。分享给大家供大家参考,具体如下: 1 __init__和__new__ __init__方法用来初始化类实例;__new__方法用来创建类实例。...

python 搭建简单的http server,可直接post文件的实例

server: #coding=utf-8 from BaseHTTPServer import BaseHTTPRequestHandler import cgi class Po...

python批量创建指定名称的文件夹

本文实例为大家分享了python批量创建指定名称的文件夹具体代码,供大家参考,具体内容如下 继删除多余文件之后,做了一些数据处理,需要重新保存数据,但文件夹的名称又不能改 所以只能创建新...