黑猴子的家:Python sure _while
2019-01-10 本文已影响24人
黑猴子的家
限定3次,如果三次都输入错误,进入是否选择重新尝试3次
code
# Author:黑猴子
age_of_heihouzi = 18
count = 0
while count <3:
guess_age = int(input("guess age:") )
if guess_age == age_of_heihouzi :
print("yes, you got it. ")
break
elif guess_age > age_of_heihouzi:
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
运行
guess age:12
think bigger!
guess age:88
think smaller...
guess age:46
think smaller...
do you want to keep guessing..?y
guess age:18
yes, you got it.