Python第一周_所写代码_练习_三次循环

写法一:
age_of_kunpeng = 21
for i in range(3):
guess_age = int(input("guess:"))
if guess_age == age_of_kunpeng:
print("yes , you got it!")
break
elif guess_age > age_of_kunpeng:
print("mybe think smaller...")
else:
print("mybe think bigger,my firend.")
else:
print("you have trried too many times..get fuck off!")

写法二:
age_of_kunpeng = 21
count = 0
while count <3:
guess_age = int(input("guess:"))
if guess_age == age_of_kunpeng:
print("yes , you got it!")
break
elif guess_age > age_of_kunpeng:
print("mybe think smaller...")
else:
print("mybe think bigger,my firend.")
count +=1
else:
print("you have trried too many times..get fuck off!")


方法二:优化(添加了继续流程)
count = 0
while count <3:
guess_age = int(input("guess:"))
if guess_age == age_of_kunpeng:
print("yes , you got it!")
break
elif guess_age > age_of_kunpeng:
print("mybe think smaller...")
else:
print("mybe think bigger,my firend.")
count +=1
if count == 3:
countne_confirm = input("do you want to keep guessing...?")
if countne_confirm != 'n':
count = 0
else:
print("you have trried too many times..get fuck off!")



posted @ 2019-12-12 13:42  xilingKunPeng  阅读(305)  评论(0)    收藏  举报