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实现颜色rgb和hex相互转换的函数

本文实例讲述了python实现颜色rgb和hex相互转换的函数。分享给大家供大家参考。具体分析如下: 下面的python代码提供了两个函数分别用来将rgb表示的颜色转换成hex值,hex...

Python中模块(Module)和包(Package)的区别详解

1. 模块(Module) 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护。 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文...

Python随机生成身份证号码及校验功能

GitHub : https://github.com/jayknoxqu/id-number-util 身份组成方式 中华人民共和国国家标准GB 11643-1999《公民身份号码》中...

Python实现求一个集合所有子集的示例

方法一:回归实现 def PowerSetsRecursive(items): """Use recursive call to return all subsets of it...

Python实现的读取文件内容并写入其他文件操作示例

Python实现的读取文件内容并写入其他文件操作示例

本文实例讲述了Python实现的读取文件内容并写入其他文件操作。分享给大家供大家参考,具体如下: 文件目录结构,如图: read_file.py是工作文件,file_test.py是读取...