美文网首页
Python猜数小游戏

Python猜数小游戏

作者: 南少cc | 来源:发表于2017-04-14 16:30 被阅读0次

    设定目标值为20,允许最多猜三次,对与否都会退出程序:
    <pre>num = 20
    count = 0
    while count < 3:
    guess_num = int(input('age:'))
    if guess_num == num:
    print('you got it !')
    break
    elif guess_num > num:
    print('猜大了!')
    else:
    print('猜小了!')
    count = count + 1

    若要三次之后仍能继续,加入如下代码:

    if count == 3:

    countine_confirm = input('do you want to keep guessing...?')

    if countine_confirm != 'n':

    count = 0

    else:
    print('再接再厉!')</pre>

    相关文章

      网友评论

          本文标题:Python猜数小游戏

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