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

 1 # -*- coding:utf-8 -*-
 2 import random
 3 
 4 # best of three
 5 def finger_guess():
 6     rule = {1:'rock', 2:'paper', 3:'scissor'}
 7     win_way = [['rock', 'scissor'], ['paper', 'rock'], ['scissor', 'paper']]
 8     num_list = [1, 2, 3]
 9     count = 0
10     person_score = 0
11     computer_score = 0
12     while count < 3:
13         person = raw_input('please input your choice:\n1.rock\n2.paper\n3.scissor\n')
14         computer = random.choice([1, 2, 3])
15         try:
16             person = int(person)
17             if person in num_list:
18                 print 'your: %s, computer: %s' %(rule[person], rule[computer])
19                 if rule[person] == rule[computer]:
20                     print 'Same! One more try!'
21                     continue
22                 for item in win_way:
23                     if rule[person] == item[0] and rule[computer] == item[1]:
24                         print 'Win once! Come on!'
25                         person_score += 1
26                     if rule[person] == item[1] and rule[computer] == item[0]:
27                         print 'Lose once! Never mind!'
28                         computer_score += 1
29             else:
30                 print 'Are you kidding me! Please respect the Holy Game!'
31                 continue
32             count += 1
33             if computer_score == 2 or person_score == 2:
34                 break
35         except ValueError:
36             print 'Please input num in [1, 2, 3], Stupid!'
37     return person_score, computer_score
38 
39 print 'This is a game called finger_guess, you have three choices.\nWanna beat the AI, let us try!'
40 person_score, computer_score = finger_guess()
41 print 'final score:\nyour:%d computer:%d' %(person_score, computer_score)
42 if person_score > computer_score:
43     print 'You get it'
44 else:
45     print 'You are so pussy!!'

 

转载于:https://www.cnblogs.com/laresh/p/6526422.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值