作业,输入名字密码,按dict插入到list,非法字符显示*

user_list=[]
_bool = True
board = ['张三','李小四','王二麻子']
while _bool:
    dic = {}
    username = input('账号>>>')
    if username.lower() == 'q':
        _bool = False  #如果需要多个地方终止循环尽量用bool,也可以用break、
        continue  #必须加上
    elif username in board:
        # print('请不要输入非法字符')
        for x in range(len(username)):
            # print(username[x])
            username = username.replace(username[x],'*')
        # for x in username:
        #     print(x)
        #     username = x.replace(x,'*'*len(username))
    password = input('密码>>>')
    dic['username'] = username
    dic['password'] = password
    user_list.append(dic)
    print(user_list)

 

posted @ 2019-02-25 16:16  ChenGouDa  阅读(124)  评论(0编辑  收藏  举报