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实现删除文件与目录的方法。分享给大家供大家参考。具体实现方法如下: os.remove(path) 删除文件 path. 如果path是一个目录, 抛出 OSE...

对json字符串与python字符串的不同之处详解

API的应用通常会处理json数据,刚好今天看到了json字符串和python字符串的区别,放一段代码,区别一下子就看出来,的确json 库为处理Json 数据提供了不少的便利。 i...

Python中__call__用法实例

本文实例讲述了Python中__call__的用法,分享给大家供大家参考之用。具体方法如下: 先来看看如下示例代码: #call.py 一个class被载入的情况下。 class N...

Swift 3.0在集合类数据结构上的一些新变化总结

一、Array数组的更改 array数组中修改的API示例如下: //创建大量相同元素的数组 //创建有10个String类型元素的数组,并且每个元素都为字符串"Hello" //s...

Queue 实现生产者消费者模型(实例讲解)

Python中,队列是线程间最常用的交换数据的形式。 Python Queue模块有三种队列及构造函数: 1、Python Queue模块的FIFO队列先进先出。 class Queue...