标签:
1 import random 2 secret=random.randint(1,99) 3 guess=0 4 tries=0 5 print secret 6 print"Alex,I have a secret,It is a number from 1 to 99,you have 6 tries." 7 while guess!=secret and tries<6: 8 guess=input("Enter you guess number:") 9 if guess<secret: 10 print " too low" 11 elif guess>secret: 12 print"too hight" 13 tries+=1 14 if guess==secret: 15 print"congratulations" 16 else: 17 print "no more tries"
1.关于tries+=1,在python中,语句块不会单独引进新的作用域,tries还是全局变量,while中改变tries会使tries变量的值改变。
2.逻辑判断。(1)guess!=secret并且tries<6.(2)guess==secret,(3)tries>=6。当(1)不满足时,有(2)(3)两种情况。
标签:
原文地址:http://www.cnblogs.com/queqiaoshui/p/5792318.html