1). 假设系统中的用户名"root",密码为"westos";
2). 如果用户输入用户名和密码均正确显示"login ok"
如果用户名错误,显示"user is not exist"
如果密码错误,显示"password is no ok"
3). 只有三次登陆机会,超过三次,显示"count is bigger than 3"
#!/usr/bin/env python#!conding=utf-8
username="root"
password="westos"for LoginTime in range(1,5):
if LoginTime==4:
print "count is bigger than 3!"break
InName=raw_input("please input username:")
InPass=raw_input("please input password:")
if InName!=username:
print "user is not exist!"
elif InPass!=password:
print "passwd is not ok!!"else:
print "login ok"break
测试结果:
Q2. 编写乘法表;
#!/usr/bin/env python#!conding=utf-8for i in range(1,10):
for j in range(1,10):
print i,"*",j,"=",i*j," ",
if j==i:
break
print "\n"