python循环剪刀石头布_python 实现剪刀石头布(三局两胜)

# -*- 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!!'

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

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

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

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

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

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

Python 基础语法(三)

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

python学习第三次记录

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

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

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

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

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

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

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

随机推荐

一切Web的基础----HTTP

HTTP 是基于 TCP/IP 协议的应用层协议.它不涉及数据包(packet)传输,主要规定了客户端和服务器之间的通信格式,默认使用80端口.HTTP协议基于TCP连接,该协议针对TCP连接上的数据 ...

iOS与日期相关的操作

// Do any additional setup after loading the view, typically from a nib. //得到当前的日期 注意week1是星期天 NSDat ...

jquery返回顶部

// 返回顶部 var fixed_totop = $('.back_top').on('click',function(){ $('html, body').animate({scrollTop: ...

ios 从前台返回到回台 从后台返回到前台 或者 支付宝支付订单后 对界面进行操作

正常情况下,在AppDelegate中实现下面两个方法,能够监听从后台恢复到前台 - (void)applicationDidEnterBackground:(UIApplication *)appl ...

directive例子2

(function() { angular.module('app.widgets') .directive('bsModalPlus', function($window, $sce, $modal ...

Video Processing subsystem例程分析

Video Processing subsystem例程分析 1.memory_ss模块 slave端口: S00: 连接设备: microblaze_ss----M_AXI_DC 时钟来源: S01 ...

centos6.x下安装maven

转自:http://www.centoscn.com/image-text/install/2014/0507/2923.html 1.下载maven包首先从官网上 http://maven.apac ...

java中URL 的编码和解码函数

java中URL 的编码和解码函数java.net.URLEncoder.encode(String s)和java.net.URLDecoder.decode(String s);在javascri ...

CentOS6安装Jenkins

1.安装最新版JDK(作为JENKINS运行环境)# mount -t cifs //192.168.8.1/share /mnt -o username=share,password=share,n ...

myschool 相思树

题目描述 一群妖王排成一排站在苦情巨树下,寻找自己的转世恋人.虽然都是妖王,但按照涂山的规定必须进行标号,标号为1的妖王排在最后面,标号为n的妖王排在最前面.每个妖王只有一个妖力值a[i]表示它们现在 ...

你可能感兴趣的:(python循环剪刀石头布)