设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

猜密码游戏

[复制链接]

1

主题

0

好友

50

积分

注册会员

Rank: 2

楼主
发表于 2014-6-21 18:15:03 |显示全部楼层
  1. #!/usr/bin/env python
  2. #coding:UTF-8

  3. from random import randint

  4. print '*'*6+'猜密码游戏'+'*'*16
  5. print '*'*6+'密码由0-9组成且不重复'+'*'*6
  6. password=[]
  7. pw=''
  8. A=0
  9. B=0
  10. i=1
  11. while i<=4:
  12.     rand=randint(0,9)
  13.     if rand not in password:
  14.         password.append(rand)
  15.         pw+=str(rand)
  16.         i+=1
  17. guess=raw_input('输入你猜的密码\nGuess=')
  18. guess_list=[]
  19. for s in guess:
  20.     guess_list.append(int(s))
  21. i=0
  22. while i<4:
  23.     if password[i]==guess_list[i]:
  24.         A+=1
  25.     elif password[i] in guess_list:
  26.         B+=1
  27.     i+=1

  28. print '正确密码:'.decode('utf8')+'%s' %(int(pw))
  29. print 'Result:%dA%dB' %(A,B)
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-3 19:19 , Processed in 0.025541 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部