概述
写法一:
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第一周_所写代码_练习_三次循环所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复