Python第一天课后作业

思维脑图
这里写图片描述

第一题

用户登陆:
1). 假设系统中的用户名“root”,密码为“westos”;
2). 如果用户输入用户名和密码均正确显示“login ok”
如果用户名错误,显示“user is not exist”
如果密码错误,显示“password is no ok”
3). 只有三次登陆机会,超过三次,显示“count is bigger than 3”

count=0
while count<3:
    username = input("请输入用户名:")
    password = input("请输入密码:")
    if username=='root' and password=='westos':
        print("login ok")
        break
    else:
        count+=1
        if username!='root':
            print("user is not exist")
        else:
            print("password is no ok")
if count>=3:
    print("count is bigger than 3!")

运行结果:
正确输入
这里写图片描述

错误输入三次
这里写图片描述

第二题
编写乘法表

for i in range(1,10):
    print("\n")
    for j in range(1,i+1):
        print ("%d * %d = %d" %(i,j,i*j))

运行效果
1.由于误安装高版本python(版本号3.6.2),一时不知如何取消换行
2.输出格式尚待优化,故截图不完整
这里写图片描述

猜你喜欢

转载自blog.csdn.net/siyuexiangxian/article/details/77543527
今日推荐