# -*- coding:utf-8 -*-
import random # best of three
def finger_guess():
rule = {1:'rock', 2:'paper', 3:'scissor'}
win_way = [['rock', 'scissor'], ['paper', 'rock'], ['scissor', 'paper']]
num_list = [1, 2, 3]
count = 0
person_score = 0
computer_score = 0
while count < 3:
person = raw_input('please input your choice:\n1.rock\n2.paper\n3.scissor\n')
computer = random.choice([1, 2, 3])
try:
person = int(person)
if person in num_list:
print 'your: %s, computer: %s' %(rule[person], rule[computer])
if rule[person] == rule[computer]:
print 'Same! One more try!'
continue
for item in win_way:
if rule[person] == item[0] and rule[computer] == item[1]:
print 'Win once! Come on!'
person_score += 1
if rule[person] == item[1] and rule[computer] == item[0]:
print 'Lose once! Never mind!'
computer_score += 1
else:
print 'Are you kidding me! Please respect the Holy Game!'
continue
count += 1
if computer_score == 2 or person_score == 2:
break
except ValueError:
print 'Please input num in [1, 2, 3], Stupid!'
return person_score, computer_score print 'This is a game called finger_guess, you have three choices.\nWanna beat the AI, let us try!'
person_score, computer_score = finger_guess()
print 'final score:\nyour:%d computer:%d' %(person_score, computer_score)
if person_score > computer_score:
print 'You get it'
else:
print 'You are so pussy!!'

python 实现剪刀石头布(三局两胜)的更多相关文章

  1. 猜拳游戏三局两胜------java实现代码

    package com.javasm.exerices02; import java.util.ArrayList; import java.util.List; import java.util.R ...

  2. 石头剪刀布三局两胜(平局重来break用法)

  3. Python,while循环小例子--猜拳游戏(三局二胜)

    Python,while循环小例子--猜拳游戏(三局二胜) import random all_choice = ['石头', '剪刀', '布'] prompt = '''(0)石头 (1)剪刀 ( ...

  4. 进击的Python【第三章】:Python基础(三)

    Python基础(三) 本章内容 集合的概念与操作 文件的操作 函数的特点与用法 参数与局部变量 return返回值的概念 递归的基本含义 函数式编程介绍 高阶函数的概念 一.集合的概念与操作 集合( ...

  5. Python 基础语法(三)

    Python 基础语法(三) --------------------------------------------接 Python 基础语法(二)------------------------- ...

  6. python学习第三次记录

    python学习第三次记录 python中常用的数据类型: 整数(int) ,字符串(str),布尔值(bool),列表(list),元组(tuple),字典(dict),集合(set). int.数 ...

  7. python 历险记(三)— python 的常用文件操作

    目录 前言 文件 什么是文件? 如何在 python 中打开文件? python 文件对象有哪些属性? 如何读文件? read() readline() 如何写文件? 如何操作文件和目录? 强大的 o ...

  8. 3.Python爬虫入门三之Urllib和Urllib2库的基本使用

    1.分分钟扒一个网页下来 怎样扒网页呢?其实就是根据URL来获取它的网页信息,虽然我们在浏览器中看到的是一幅幅优美的画面,但是其实是由浏览器解释才呈现出来的,实质它是一段HTML代码,加 JS.CSS ...

  9. 记录在window平台安装python的第三库(py,whl)

    在下载python的第三库文件的时候,有些库文件有exe的发行版,但是有些第三库并没有找到针对于window的可执行文件安装包即exe文件,而只有源代码文件即py文件,和whl文件. 下面记录一下在w ...

随机推荐

  1. 解决mac下安装yeoman时没有权限问题

    在mac下安装yeoman经常会出现如下图错误: 解决办法:在命令行执行-- sudo chown -R $USER /usr/local/lib/node_modules 回车就OK

  2. 上机练习2 生成计算机ID

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  3. C 碎片一 计算机知识

    一.计算机知识 1, 计算机组成及工作原理 计算机是硬件和软件的结合体.硬件由主机箱和外部设备组成,主机主要包括CPU.内存.主板.硬盘.光驱.各种扩展卡.连接线.电源等:外部设备包括鼠标.键盘等.软 ...

  4. Linux - 数值运算

    Shell - 数值运算 因为shell脚本是属于弱语言,没有变量类型的概念,所以定义变量会默认为字符串.就算看上去是一个数字,当直接进行计算时,就会出错: x=1 echo $x+=1 # 输出1+ ...

  5. asp.net 子域跨域 带cookie

    先来一个老外的解决方案: http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api ...

  6. Flask之目录结构

    学习Flask,整合其目录结构也是比较重要的.一个最基础的Flask目录如下所示: 一.SQLAlchemy-utils 由于sqlalchemy中没有提供choice方法,所以借助SQLAlchem ...

  7. CentOS服务器初始化设置

    CentOS服务器初始化设置 以阿里云服务器为例 一.挂载硬盘 1.磁盘分区 fdisk -l #查看设备,一般可以看到设备名为/dev/xvdb,或者为/dev/vdb(阿里云io优化型) fdis ...

  8. [Asp.Net] web api 部署注意事项

    在将web api项目部署到IIS上的时候 要将应用程序池设置成.net framework 4.0版本

  9. [转]超全!iOS 面试题汇总

    转自:http://www.cocoachina.com/programmer/20151019/13746.html 1. Object-c的类可以多重继承么?可以实现多个接口么?Category是 ...

  10. getline()读入一整行

    string line; getline(cin, line); cin不能读入空行,用getline可以读入空行.