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 使用pygame工具包实现贪吃蛇游戏(多彩版)

python 使用pygame工具包实现贪吃蛇游戏(多彩版)

今天我们用python和python的工具包pygame来编写一个贪吃蛇的小游戏 贪吃蛇游戏功能介绍 贪吃蛇的游戏规则如下: 通过上下左右键或者WASD键来移动蛇来,让它吃到食物,...

Python3实现取图片中特定的像素替换指定的颜色示例

Python3实现取图片中特定的像素替换指定的颜色示例

本文实例讲述了Python3实现取图片中特定的像素替换指定的颜色。分享给大家供大家参考,具体如下: 1、原始图片 2、修改脚本: # -*- coding:utf-8 -*- #!...

详解Numpy中的数组拼接、合并操作(concatenate, append, stack, hstack, vstack, r_, c_等)

详解Numpy中的数组拼接、合并操作(concatenate, append, stack, hstack, vstack, r_, c_等)

Numpy中提供了concatenate,append, stack类(包括hsatck、vstack、dstack、row_stack、column_stack),r_和c_等类和函数...

跟老齐学Python之使用Python操作数据库(1)

在上一讲中已经连接了数据库。就数据库而言,连接之后就要对其操作。但是,目前那个名字叫做qiwsirtest的数据仅仅是空架子,没有什么可操作的,要操作它,就必须在里面建立“表”,什么是数...

Python语言描述连续子数组的最大和

题目描述 HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学。今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决。...