美文网首页
Python-if else while for

Python-if else while for

作者: GaoYuan117 | 来源:发表于2018-10-07 19:51 被阅读4次
_pwd = 123

count = 0

while count < 3:

    pwd = int(input("pwd:"))

    if _pwd == pwd:
        print("密码输入正确")
        break
    elif _pwd > pwd:
        print("猜的太小了")
    else:
        print("猜的太大了")

    count += 1
else:
    print("游戏结束")

for循环

for i in range(3):

    pwd = int(input("pwd:"))

    if _pwd == pwd:
        print("密码输入正确")
        break
    elif _pwd > pwd:
        print("猜的太小了")
    else:
        print("猜的太大了")

    count += 1
else:
    print("游戏结束")

for i in range(20, 30, 2):
    print(i)

continue 结束本次循环
break 结束整个循环

相关文章

网友评论

      本文标题:Python-if else while for

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