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对列表排序的方法。分享给大家供大家参考。具体分析如下: 1、sort()函数 sort()函数使用固定的排序算法对列表排序。sort()函数对列表排序时改变了原...

解决Django一个表单对应多个按钮的问题

需求: 在django中,有时候我们需要在一个表单中设置多个按钮实现不同的功能。 解决方法: 为不同按钮添加不同name属性,然后再后台判断name值。python2环境下,例如: 我们...

python argparser的具体使用

一.正常运行: 咱们随便写个文件: # test.py import argparse ap = argparse.ArgumentParser() ap.add_argumen...

flask中的wtforms使用方法

flask中的wtforms使用方法

一、简单介绍flask中的wtforms WTForms是一个支持多个web框架的form组件,主要用于对用户请求数据进行验证。 安装: pip3 install wtforms...

python实现报表自动化详解

python实现报表自动化详解

本篇文章将介绍: xlwt 常用功能 xlrd 常用功能 xlutils 常用功能 xlwt写Excel时公式的应用 xlwt写入特定目录(路径设置) xlwt Python语言中,写...