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

相关文章

基于pandas将类别属性转化为数值属性的方法

基于pandas将类别属性转化为数值属性的方法

离散特征的编码分为两种情况: 1、离散特征的取值之间没有大小的意义,比如color:[red,blue],那么就使用one-hot编码 2、离散特征的取值有大小的意义,比如size:[...

如何使用Python脚本实现文件拷贝

如何使用Python脚本实现文件拷贝

这篇文章主要介绍了如何使用Python脚本实现文件拷贝,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.实现目的 统一时间对服务器...

Django组件之cookie与session的使用方法

Django组件之cookie与session的使用方法

一、引子 http协议是无状态的,就是它不会记录请求和响应的任何信息,比如你访问一个服务器的一个网页时,先要你登录一下,然后进入网页,但当你要进入这个服务器的另一个网页时,它照常不会知道...

python中比较两个列表的实例方法

cmp() 方法用于比较两个列表的元素。 cmp()方法语法: cmp(list1, list2) 参数: list1 -- 比较的列表。list2 -- 比较的列表。 返回值:...

python3基于OpenCV实现证件照背景替换

本文实例为大家分享了python3实现证件照背景替换的具体代码,供大家参考,具体内容如下 import cv2 import numpy as np img=cv2.imread(...