用项目自学python for循环,while循环,if-else条件判断

学习目录:

1.猜数字大小游戏 for循环版本

2.猜数字大小游戏while循环版本

3.用户登陆模拟

4.作业:重复错误登陆三次,锁定用户

 

开始项目:

猜数字大小游戏 for循环版本:

for i in range(3):
    age_of_oldboy = 65
    age = int(input("guess age:"))

    if age ==age_of_oldboy:
        print("right! you get it!")
        break
    elif age < age_of_oldboy:
        print("too small")
    else:
        print("too big")
else:
    print("tried too mant times, fuck off...")

 

 

猜数字大小游戏while循环版本:

account = 0
while account < 3:
    account +=1
    age_of_oldboy = 65
    age = int(input("guess age:"))

    if age ==age_of_oldboy:
        print("right! you get it!")
        break
    elif age < age_of_oldboy:
        print("too small")
    else:
        print("too big")
else:
    print("tried too mant times, fuck off...")

用户登陆模拟:

account = 0
while account < 3:
    account +=1
    age_of_oldboy = 65
    age = int(input("guess age:"))

    if age ==age_of_oldboy:
        print("right! you get it!")
        break
    elif age < age_of_oldboy:
        print("too small")
    else:
        print("too big")

    if account ==3:
        continue_comfire = input("do you want to keep guessing..y/n?")
        if continue_comfire != "n":
            account = 0

 

重复错误登陆三次,锁定用户:

count = 0
while 1:
    _user_name = "han"
    _password = "123456"

    user_name = input('user_name:')
    password = input('password:')

    if _user_name ==user_name:
        print("welcome {name} to login..".format(name = user_name))
        break
    else:
        print("invalid username or password!")
        count +=1

    if count == 3:
            print('user locking !')
            if _user_name ==user_name:
                print('user locking !')

 

---恢复内容结束---

posted @ 2018-03-12 10:55  python你这小蟒鞋  阅读(163)  评论(0编辑  收藏  举报