tag = True
while tag:
name = input('please your name:')
psw = input('please your password:')
if name == 'seven' and psw == '123':
print('login successful...')
else:
print('user or password err...')
tag = True
count = 0
while tag:
if count == 3:
print('Too many errors...')
break
name = input('please your name:')
psw = input('please your password:')
if name == 'seven' and psw == '123':
print('log in successful...')
tag = False
else:
print('user or password err...')
count += 1
print('...Its over')
#方法一:
tag = True
i = 0
j = 0
while tag:
if i == 3 or j == 3:
print('Too many errors...')
break
name = input('please your name:')
psw = input('please your password:')
if name == 'seven':
if psw == '123':
print('log in successful...')
else:
print('password err...')
i += 1
elif name == 'alex':
if psw == '123':
print('log in successful...')
else:
print('password err...')
j += 1
else:
print('user err...')
print('---Its over---')
'''这代码感觉太low了 '''
#方法二:
dic = {
'seven': {'psw': '123', 'count': 0},
'alex': {'psw': '456', 'count': 0},
'wood':{'psw':'000','count':0}
}
tag = True
while tag:
user_name = input('please your name:')
if not user_name in dic:
print('...No username exists...')
continue
if dic[user_name]['count'] == 3:
print('...Too many errors...')
continue
user_psw = input('please your password:')
if user_psw == dic[user_name]['psw']:
print('...log in successful...')
print('''请进行操作:
1.浏览列表
2.选定对象
3.开始聊天
''')
while tag:
choose = input('>>:')
if choose == '1':
print('浏览列表中。。。。。。')
elif choose == '2':
print('对象以选定。。。。。。')
elif choose == '3':
print('聊天中。。。。。。')
elif choose == 'quit':
tag=False
else:
print('指令无效,请重新输入。。。')
else:
print('...password err...')
dic[user_name]['count'] += 1
print('---Its over---')
count = 3
i = 2
j = 3
while count <= 100:
if count % 2 == 0:
i = i + j
else:
i = i - j
j += 1
count += 1
print(i)
count = 0
while count <= 100:
if count % 2 != 0:
print(count)
count += 1
count = 1
while count <= 100:
if count % 2 == 0:
print(count)
count += 1
dic = {
'wood': {'psw': '123', 'count': 0},
'egon': {'psw': '456', 'count': 0},
'alex': {'psw': '789', 'count': 0}
}
tag = True
while tag:
name = input('please your username:')
if not name in dic:
print('用户名不存在')
continue
if dic[name]['count'] == 3:
print('尝试次数过多,锁定')
continue
psw = input('please your password:')
if psw == dic[name]['psw']:
print('login successful...')
tag = False
else:
print('password err...')
dic[name]['count'] += 1
1.可以支持多个用户登录 (提示,通过列表存多个账户信息)
2.用户3次认证失败后,退出程序,再次启动程序尝试登录时,
还是锁定状态(提示:需把用户锁定的状态存到文件里)
dic={
'egon1':{'password':'123','count':0},
'egon2':{'password':'123','count':0},
'egon3':{'password':'123','count':0},
}
count=0
while True:
name=input('u>>: ')
if name not in dic:
print('用户不存在')
continue
with open('db.txt','r') as f:
lock_users=f.read().split('|')
if name in lock_users:
print('用户%s已经被锁定' %name)
break
if dic[name]['count'] > 2:
print('尝试次数过多,锁定')
with open('db.txt','a') as f:
f.write('%s|' %name)
break
password=input('p>>: ')
if password == dic[name]:
print('登录成功')
break
else:
print('用户名或密码错误')
dic[name]['count']+=1