美文网首页python入门基础
黑猴子的家:Python sure _while

黑猴子的家:Python sure _while

作者: 黑猴子的家 | 来源:发表于2019-01-10 15:43 被阅读24次

限定3次,如果三次都输入错误,进入是否选择重新尝试3次
code

# Author:黑猴子

age_of_heihouzi = 18

count = 0
while count <3:
    guess_age = int(input("guess age:") )
    if guess_age == age_of_heihouzi :
        print("yes, you got it. ")
        break
    elif guess_age > age_of_heihouzi:
        print("think smaller...")
    else:
        print("think bigger!")
    count +=1
    if count == 3:
        countine_confirm = input("do you want to keep guessing..?")
        if countine_confirm != 'n':
            count =0

运行

guess age:12
think bigger!
guess age:88
think smaller...
guess age:46
think smaller...
do you want to keep guessing..?y
guess age:18
yes, you got it. 

相关文章

网友评论

    本文标题:黑猴子的家:Python sure _while

    本文链接:https://www.haomeiwen.com/subject/aaearqtx.html