python 循环while和for in简单实例

python 循环while和for in简单实例

#!/uer/bin/env python
# _*_ coding: utf-8 _*_

lucknumber = 5
b = 0

while b <3:
  print('guss count:',b)
  a = int(input('you guse number'))
  if a > lucknumber:
    print ('youaerbiger')
  elif a == lucknumber:
    print ('youare righet')
    break                 #跳出这个层级的循环
  else :
    print ('you aer smaller')
  b +=1                  #在while循环中,+=1 是必须循环体
else:
  print ("Too many retrys!")

#________________________________________________

for i in range(3):
  a = int(input('you guse number'))   #注意用int()表示输出的是 数字类型
  if a > lucknumber:
    print ('youaerbiger')
  elif a == lucknumber:
    print ('youare righet')
    break
  else :
    print ('you aer smaller')
else:
  print ("Too many retrys!")

相关推荐