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

相关文章

opencv-python 提取sift特征并匹配的实例

我就废话不多说,直接上代码吧! # -*- coding: utf-8 -*- import cv2 import numpy as np from find_obj import...

查看python下OpenCV版本的方法

在命令行输入以下代码: python import cv2 cv2.__version__ 以上这篇查看python下OpenCV版本的方法就是小编分享给大家的全部内容了,希望能给...

关于Python3 lambda函数的深入浅出

我们常常看到一个这样的表达式  A=lambda x:x+1 可能会一头雾水不知道怎么计算 最基本的理解就是 def A(x): return x+1 但是理解程序不会将一个表...

Python中如何优雅的合并两个字典(dict)方法示例

前言 字典是Python中最强大的数据类型之一,本文将给大家详细介绍关于Python合并两个字典(dict)的相关内容,分享出来供大家参考学习,话不多说了,来一起看看详细的介绍吧。 一行...

Python实现读取邮箱中的邮件功能示例【含文本及附件】

本文实例讲述了Python实现读取邮箱中的邮件功能。分享给大家供大家参考,具体如下: #-*- encoding: utf-8 -*- import sys import local...