Python-if else while for

2018-10-07  本文已影响4人  GaoYuan117
_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 结束整个循环

上一篇 下一篇

猜你喜欢

热点阅读