# -*- 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. Java 多线程的实现方法

    package com.jckb; /**多线程实现的两种方法 * * @author gx * */ public class Test2 { public static void main(Str ...

  2. gitk更改主题设置打不开

    ➜ project git:(master) gitk Error in startup script: unknown color name "lime" (processing ...

  3. Eclipse升级到ADT-23.0.2 Fail 解决方法

    工具:eclipse3.7.2 升级ADT:从ADT-22.3.0到ADT-23.0.2 错误信息: Cannot complete the install because of a conflict ...

  4. C#中 String和string的区别

    string 是 System.String的别名,所以相当于声明了 using string = System.String 再者,string是C#的关键字,String是System下的类名.

  5. 改善WPF应用程序性能的10大方法 (转发)

    WPF(Windows Presentation Foundation)应用程序在没有图形加速设备的机器上运行速度很慢是个公开的秘密,给用户的感觉是它太吃资源了,WPF程序的性能和硬件确实有很大的关系 ...

  6. 如何查看与显示oracle表的分区信息

    显示分区表信息 显示数据库所有分区表的信息:DBA_PART_TABLES 显示当前用户可访问的所有分区表信息:ALL_PART_TABLES 显示当前用户所有分区表的信息:USER_PART_TAB ...

  7. SQL重复记录查询-count与group by having结合查询重复记录

    查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select  peopleId  from  p ...

  8. hihoCoder hiho一下 第二周 #1014 : Trie树(Trie树基本应用)

    思路: 完全看题目中的介绍就行了.还有里面的input写道:不保证是英文单词,也有可能是火星文单词哦.比赛结束后的提交是不用考虑26个字母之外的,都会AC,如果考虑128种可能的话,爆了内存.步骤就是 ...

  9. pat乙级1067

    1.用cin输入数据后,再用getline 输入,还是会输入cin已经输入的数据,即cin和getline互相独立. 2.题目中没有说尝试的密码不包含空格,因此不能用cin,而用getline. #i ...

  10. linux 命令——32 gzip(转)

    减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间.gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用.gzip不仅可以用 ...