python练习题-程序控制-模拟登录(一)
1.输入账号密码,判断成功,程序退出。判断失败,继续登录输入。
考察点:while和if语句的运用,及flage标志位。
python 2.7
#coding=utf-8; flage = True; while flage: user = raw_input("用户名:"); print user; pwd = input("密码:"); print pwd; if user == "tom" and pwd ==123: print "登录成功"; flage = False; else: print "登录失败";
python3
#coding=utf-8; flage = True; while flage: user = input("用户名:"); print(user); pwd = input("密码:"); print(pwd); if user == "tom" and pwd =="123": print("登录成功"); flage = False; else: print("登录失败");