while循环

法一:

!/usr/bin/env python
#_*_ coding:utf-8 _*_
count = 0
while True:
  print("count:",count)
  count +=1
  if count == 100:
    break

法二:

#!/usr/bin/env python
#_*_ coding:utf-8 _*_
age_of_jack = 26
count = 0
while count <3:
  guess_age = int(input("guess age:"))
  if guess_age == age_of_jack:
    print("yes,you got it.")
    break
  elif guess_age >age_of_jack:
    print("think smaller...")
  else:
    print("think bigger!")
  count +=1

else:

  print('you have tried too many times...fuck off.')

法三:

#!/usr/bin/env python

# -*- coding: utf-8 -*-
age_of_jack = 23
count = 0
while count <3:
  guess_age = int(input('guess age:'))
  if guess_age == age_of_jack:
    print('yes,you got it.')
    break
  elif guess_age >age_of_jack:
    print('think smaller...')
  else:
    print('think bigger!')
  count +=1
  if count == 3:
    countine_confirm = input('do you want to keep guessing?')
    if countine_confirm !='n':
      count = 0

原文地址:https://www.cnblogs.com/qlqqlq/p/8687682.html