我是靠谱客的博主 坚定未来,这篇文章主要介绍python文字游戏循环3次_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!")

最后

以上就是坚定未来最近收集整理的关于python文字游戏循环3次_Python第一周_所写代码_练习_三次循环的全部内容,更多相关python文字游戏循环3次_Python第一周_所写代码_练习_三次循环内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(116)

评论列表共有 0 条评论

立即
投稿
返回
顶部