user = "gaojun"
password ="123abc"
for i in range(3):
user = input('请输入用户名:')
password = input('请输入密码:')
if user == "gaojun" and password =="123abc":
print("欢迎!gaojun!")
break
else:
print("用户或密码错误!")
else:
print("输入次数到达3次,!")
解释:
1.定义变量user,password,并分别赋值user = "gaojun" password = "123abc";
2.用for循环限制用户输入3次;
3.用 input函数给变量user,和password赋值,并且和内存已经存储的数据“gaojun”,“123abc”作比较;
4.如果赋的值刚好等于"gaojun","123abc",那么程序打印出“欢迎!gaojun!”立即中断;
5.如果输错,输出“用户或密码错误”并且连续输错3次直接退出.
流控图: