python简单脚本1

来源:互联网 发布:最好用的p2p软件 编辑:程序博客网 时间:2024/06/05 21:02

Q1. 用户登陆v1:

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-8username="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"

测试结果:

这里写图片描述