- 帖子
- 4
- 精华
- 0
- 积分
- 36
- 阅读权限
- 10
- 注册时间
- 2016-3-24
- 最后登录
- 2016-7-7
|
- import random
- end = '4A0B'
- end_try = ''
- lst_password = []
- def creat_password():
-
- for i in range(4):
- x1 = random.randint(0,9)
- lst_password.append(x1)
-
- #print 'the password is: ' , lst_password
- return lst_password
-
- def compare():
-
- number_A = 0
- number_B = 0
- print 'Now, please guess the password!'
- for i in range(0,4):
-
- number = int(raw_input('Enter the number(0-9): '))
-
- if number == lst_password[i]:
- number_A += 1
- else:
- if number in lst_password:
- number_B += 1
- else:
- pass
- end_try = '%dA%dB' % (number_A,number_B)
- print end_try
- return end_try
-
- print 'Start Game!'
- creat_password()
- while end_try != '4A0B':
- compare()
- print 'You got the right password.Congratulitions!'
复制代码 C老师,绝对新手请教啊,为什么我这个代码,即使输出了4A0B,也结束不了呢,还是会继续让猜数字,而不会输出最后“You got the right password. Congratulitions!” |
|