- 帖子
- 2
- 精华
- 0
- 积分
- 22
- 阅读权限
- 10
- 注册时间
- 2015-5-5
- 最后登录
- 2015-5-23
|
Python新手- import random
- import re
- com1=random.sample(range(0,9),4)
- com=''.join(str(i) for i in com1)
- #print com
- while True:
- A=0
- B=0
- print "Please input four number:(input the 'end' quit the game)"
- you=raw_input()
- if you=='end':
- break
- else:
- m=re.findall(r"\b\d{4}\b",you)
- if m:
- for i in range(4):
- for j in range(4):
- if i==j:
- if you[i]==com[j]:
- A+=1
- else:
- if you[i]==com[j]:
- B+=1
- print '%dA%dB'%(A,B)
- if A==4:
- print 'you are win !'
- break
- else:
- print 'go on ... !'
-
-
- else:
- print "You input the numbers does't conform to the rules"
复制代码 |
|