Python实现简单石头剪刀布游戏

yipeiwu_com5年前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 的 Socket 编程

Socket是网络应用的基础。而Python使得网络socket编程入门变得超级简单。在这篇简介里面我们将创建一个简单服务器,用于接受和相应客户端程序的请求。 由于本人最近对 Linux...

python简单实现操作Mysql数据库

用python编写数据库的代码很方便,但是如果不想自己写sql语句,其实还有更多的讨巧办法。使用webpy的db库就是不错的一个选择。当然为了使用webpy的db,之前你还需要安装MyS...

Pytorch在dataloader类中设置shuffle的随机数种子方式

Pytorch在dataloader类中设置shuffle的随机数种子方式

如题:Pytorch在dataloader类中设置shuffle的随机数种子方式 虽然实验结果差别不大,但是有时候也悬殊两个百分点 想要复现实验结果 发现用到随机数的地方就是datalo...

Python命令行参数解析模块getopt使用实例

格式 getopt(args, options[, long_options]) 1.args表示要解析的参数. 2.options表示脚本要识别的字符.字符之间用”:”分隔,而且必须...

Djang的model创建的字段和参数详解

class test_orm(models.Model): id = models.AutoField(primary_key=True) # int自增列,必须填入参数pr...