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

相关文章

利用Celery实现Django博客PV统计功能详解

前言 前几天给网站的文章增加了pv统计,之前只有uv统计。之前没加pv统计是觉得每个用户每访问一次文章,我都需要做一次数据库写操作实在是有损性能,毕竟从用户在the5fire博客的的一...

Python中字符串与编码示例代码

在最新的Python 3版本中,字符串是以Unicode编码的,即Python的字符串支持多语言 编码和解码    字符串在内存中以Unicode表示,在操作字符串时,经常需要...

浅谈机器学习需要的了解的十大算法

浅谈机器学习需要的了解的十大算法

毫无疑问,近些年机器学习和人工智能领域受到了越来越多的关注。随着大数据成为当下工业界最火爆的技术趋势,机器学习也借助大数据在预测和推荐方面取得了惊人的成绩。比较有名的机器学习案例包括Ne...

python如何以表格形式打印输出的方法示例

python如何以表格形式打印输出的方法示例

好久不见,风水轮流转,我竟然写写写python了 近日有个小需求,要求收集统计一些信息上报,并直接在后台控制台打印,写入日志 为了美观,需要以表格形式展现数据,形如 虽说可以用 pre...

Python Xml文件添加字节属性的方法

实例如下所示: from xml.etree.cElementTree import ElementTree,Element import xlrd import re def re...