- 帖子
- 4
- 精华
- 0
- 积分
- 12
- 阅读权限
- 10
- 注册时间
- 2016-3-14
- 最后登录
- 2016-3-15
|
- import re,random
- defaultPwd = []
- i=0
- while i<4:
- defaultPwd.append(str(random.randint(0,9)))
- i += 1
- print defaultPwd
- def you_guess():
- password = raw_input('请输入密码:')
- countA=0
- countB=0
- listPwd = list(password)
- if re.match(r"\d{4}$", password) and True or False:
- for m in listPwd:
- if m in defaultPwd:
- if m == defaultPwd[listPwd.index(m)]:
- countA += 1
- else:
- countB += 1
- if '%dA%dB'%(countA,countB) != '4A0B':
- print '%dA%dB'%(countA,countB)
- you_guess()
- else:
- print '密码输入正确'
- else:
- print '请输入正确的密码'
- you_guess()
复制代码 |
|