Lesson007作业 python

来源:互联网 发布:ug攻丝编程 编辑:程序博客网 时间:2024/06/16 14:55

前言

如代码有什么不对或者不好的地方 请指出,一起进步学习谢谢

'''作业1   三次循环  输入账号密码  root  成功返回  失败提示作业2   用文件的方式进行 账号的登陆作业3     使用dict完成花名册            通过名称查找到指定的人'''def Task1():    count = 3    key = 'root'    while count > 0:        count -= 1        user = input("请输入用户名:")        password = input("请输入密码:")        if user == key and password == key:            print("登陆成功")            break        else:            print("密码或账号错误")    else:        print("三次机会已经用尽....")#字符串 和  list 实现 读取文件登陆def Task2():    myFile = open('user.txt')    listuser = []    while True:        user = myFile.readline()#获取一行        delEnter = user.replace('\n','') #去除 回车 然后返回        if len(delEnter)<2:#如果数据到达终点   结束            break        mylist = delEnter.split(' ')#分割        listuser.append(mylist)#添加进去    myFile.close()    count = 3    while count > 0:        count -= 1        user = input("请输入用户名:")        password = input("请输入密码:")        for i in listuser:            if i[0] == user and i[1] == password:                print ("登陆成功")                return 0        else:            print("密码或账号错误")    else:        print("三次机会已经用尽....")def Task3():    myFile = open('name.txt')    myTuple = myFile.readlines()    myDict={}    for tuple in myTuple:        delEnter = tuple.replace('\n', '')        mylist = delEnter.split('\t')  # 分割        myDict[mylist[1]]=mylist    while True:        strName = input("请输入要查询的名称:")        print(myDict.get(strName,"未找到此人"))