python-day1-while循环

#Author:Xk Lu
_age=28
count=0
while count<3:
age = int(input("age:"))
if age==_age:
print("you got it!")
break
elif age>_age:
print("think smaller ...")
else:
print("think bigger...")
count+=1
else:
print("you have to tried too many time.. fuck off")


while 循环优化版本
#for 循环的else 是按顺序执行  break 不走
for i in range(3):
guess_age = int(input("guess age:"))
if guess_age==age_of_oldboy:
print("yes,you got it.")
break
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger!")
else:
print("you have tried too many times.. fuck off")

for循环
for i in range(0,10,2):
print("loop",i)
程序优化 for
while count<3:
guess_age = int(input("guess age:"))
if guess_age==age_of_oldboy:
print("yes,you got it.")
break
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger!")
count+=1
if count==3:
continue_confirm=input("do you want to keep guessing..")
if continue_confirm !='n':
count=0
print(continue_confirm)
# else:
# print("you have tried too many times.. fuck off")




posted @ 2018-11-05 16:32  teven_rogers  阅读(97)  评论(0)    收藏  举报