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 数据生成excel导出(xlwt,wlsxwrite)代码实例

这篇文章主要介绍了python 数据生成excel导出(xlwt,wlsxwrite)代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以...

浅谈numpy生成数组的零值问题

今天在用numpy写sinc函数时偶然发现在x=0时函数居然能取到1,觉得很不可思议,按理来说在x=0时函数无意义,研究了一下,发现竟然时numpy在生成数组时自动用一个很小的数代替了0...

python删除不需要的python文件方法

最近在看廖老师的python教程,在看到关于文件的操作时,廖老师的其中一段关于查找电脑里的python文件,突然想把之前写的python代码给删除了,因为这是第二次看教程了。 imp...

python实用代码片段收集贴

获取一个类的所有子类 复制代码 代码如下: def itersubclasses(cls, _seen=None):     """Generator ov...

Python 'takes exactly 1 argument (2 given)' Python error

Python初学,定义urlConfig 接收参数,正常传递参数时,出现,多给了一个参数的错误问题, 定义class的函数之后,在调用的时候出现“'takes exactly 1 arg...