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]