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设计】。

相关文章

Django使用unittest模块进行单元测试过程解析

Django测试框架非常简单,首选方法是使用python标准库中的unittest模块。 Writing tests Django的单元测试使用python的unittest模块,这个...

微信跳一跳小游戏python脚本

微信跳一跳小游戏python脚本

Python编写微信小游戏“跳一跳”的运行脚本,分享给大家。 更新了微信后发现了一款小游戏跳一跳,但是玩了一下午最高才达到200,每次差点破纪录后总是手抖就挂掉了,气的想要砸手机。闲来无...

python基础知识小结之集合

集合 特点:集合对象是一组无序排列的可哈希的值:集合成员可以做字典的键,与列表和元组不同,集合无法通过数字进行索引。此外,集合中的元素不能重复。  定义 set() -...

selenium 安装与chromedriver安装的方法步骤

selenium 安装与chromedriver安装的方法步骤

安装 selenium可以直接可以用pip安装。 pip install selenium chromedriver的安装一定要与Chrome的版本一致,不然就不起作用(不要问我是...

对Python中的条件判断、循环以及循环的终止方法详解

对Python中的条件判断、循环以及循环的终止方法详解

条件判断 条件语句是用来判断给定条件是否满足,并根据判断所得结果从而决定所要执行的操作,通常的逻辑思路如下图; 单次判断 形式 if <判断条件>: <执行&g...