渡人自渡 发表于 2018-8-10 09:40:00

python for循环

#!/usr/bin/env   python  
# -*- coding:utf-8 -*-
  
age_of_xcn = 20
  
count = 0
  
while count < 3:
  
    guess_age = int(input("guess age:"))
  
    if guess_age == age_of_xcn:
  
      print("yes,you got it")
  
      break
  
    elif guess_age > age_of_xcn:
  
      print("think smaller")
  
    else:
  
      print("think bigger")
  
    count += 1
  
    if count == 3:
  
      confirm = input("do you want to keep ?")
  
      if confirm != 'n':
  
            count = 0
  

  
执行结果:
  
guess age:1
  
think bigger
  
guess age:2
  
think bigger
  
guess age:3
  
think bigger
  
do you want to keep ?ere
  
guess age:
页: [1]
查看完整版本: python for循环