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!!'
python 实现剪刀石头布(三局两胜)的更多相关文章
- 猜拳游戏三局两胜------java实现代码
package com.javasm.exerices02; import java.util.ArrayList; import java.util.List; import java.util.R ...
- 石头剪刀布三局两胜(平局重来break用法)
- 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 ...
随机推荐
- Python Unittest - Test Fixtures 测试夹具
一.什么是测试夹具 定义单个或者多个测试所需的环境准备(setUp),以及环境清理(tearDown). 例:连接数据库,或者创建Selenium WebDriver driver实例 二.测试夹具有 ...
- js中去掉字符中间空格和首尾空格
转载: https://www.jb51.net/article/109522.htm 1. 去掉字符串前后所有空格: 代码如下: ? 1 2 3 4 function Trim(str) { ...
- k8s的ingress使用
ingress 可以配置一个入口来提供k8s上service从外部来访问的url.负载平衡流量.终止SSL和提供基于名称的虚拟主机. 配置ingress的yaml: 要求域名解析无误 要求servic ...
- POJ 2891 Strange Way to Express Integers 中国剩余定理MOD不互质数字方法
http://poj.org/problem?id=2891 711323 97935537 475421538 1090116118 2032082 120922929 951016541 1589 ...
- HDU 5775 L - Bubble Sort 树状数组
给定一段冒泡排序的代码,要求输出每个数字能到达的最右边的位置和最左边的位置的差 因为那段冒泡排序的代码是每次选取一个最小的数,放在左边的,所以,每个数最多能到达右边的位置应该是起始位置i+右边有多少个 ...
- (转)Linux下PS1、PS2、PS3、PS4使用详解
Linux下PS1.PS2.PS3.PS4使用详解 原文:http://www.linuxidc.com/Linux/2016-10/136597.htm 1.PS1——默认提示符 如下所示,可以通过 ...
- 【Unity3D】Tags和Layers
Tags和Layers分别表示是Unity引擎里面的标签和层,他们都是用来对GameObject进行标识的属性,Tags常用于单个GameObject,Layers常用于一组的GameObject.添 ...
- iOS开发ReactiveCocoa学习笔记(三)
RAC常用用法: 1.监听按钮的点击事件: UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame ...
- C++中构造函数的写法
class Circle { public: Circle(float r); private: float radius; }; Circle::Circle(float r) { radius = ...
- 使用腾讯IP分享计划网站中的纯JS省市区三级联动
JS地址:http://ip.qq.com/js/geo.js 实例如下: <!DOCTYPE html> <html> <head> <title>省 ...