写法一:
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!")
最后
以上就是坚定未来最近收集整理的关于python文字游戏循环3次_Python第一周_所写代码_练习_三次循环的全部内容,更多相关python文字游戏循环3次_Python第一周_所写代码_练习_三次循环内容请搜索靠谱客的其他文章。
发表评论 取消回复