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编程实现的简单神经网络算法示例

本文实例讲述了Python编程实现的简单神经网络算法。分享给大家供大家参考,具体如下: python实现二层神经网络 包括输入层和输出层 # -*- coding:utf-8 -*-...

Python+OpenCV+pyQt5录制双目摄像头视频的实例

Python+OpenCV+pyQt5录制双目摄像头视频的实例

起因 说起来录制视频,我们可能有很多的软件,但是比较坑的是,好像很少的软件支持能够同时录制两个摄像头的视频,于是我们用python自己写一个。要是OpenCV+python。貌似很简单就...

centos6.8安装python3.7无法import _ssl的解决方法

公司运维提供的服务器是centos6.8,打算在上面装python3.7,结果费尽周折,按照网上的步骤python3.7能成功安装,但是import ssl却报找不到_ssl模块的错误:...

在漏洞利用Python代码真的很爽

不知道怎么忽然想看这个,呵呵 小我的python的反shell的代码 #!/usr/bin/python # Python Connect-back Bac...

python 多线程串行和并行的实例

如下所示: #coding=utf-8 import threading import time import cx_Oracle from pprint import pprint...