首页 > 代码库 > day13

day13

1.猜年龄,最多输入三次

count = 1
age = 8
while count <= 3:
    guess_age = int(input("please input your age: "))
    if guess_age == age:
        print("You‘re right")
        exit()
    elif count == 3:
        exit()
    else:
        print("try agin..")
        count = count + 1

 2.猜年龄 ,每隔3次,问他一下,还想不想继续玩,y,n

count = 1
age = 18
while True:
    guess_age = int(input("please input your age: "))
    if guess_age == age:
        print("You‘re right")
        exit()
    elif (count % 3) == 0:
        count += 1
        play = input("do you want to paly{y|n}")
        if play == "y":
            continue
        else:
            exit()
    else:
        print("you‘re wrong")
        count +=1

3.编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定

import os

count = 1
name = "tom"
passwd = "123456"
while count <= 3:
    guess_name = input("please input your name: ")
    guess_passwd = input("please input your password: ")
    if guess_name == name and guess_passwd == passwd:
        print("welcome..")
        exit()
    elif count == 3:
        os.system("sed -i ‘/tom/s/bin\/bash/sbin\/nologin/‘ /etc/passwd")
        print("Your account is locked...哈哈")
        exit()
    else:
        print("try agin..")
        count = count + 1

  

day13