#输出等腰三角形
i = 1 while i <= 5: print(" "*(5-i),end = "") j = 1 while j <= 2*i-1: print("*",end = "") j += 1 print("") i += 1
#for循环输出9*9乘法表
for j in range(1,10): for i in range(1,j+1): print(f"{i}*{j}={i*j}",end = "\t") print(" ")
#用户登录系统与检验
num = 0 for i in range(3): num += 1 username = input("请输入用户名:") password = input("请输入密码:") if username =="admin": if password == "888": print("登陆成功") break else: print("密码错误") print(f"你还有{3-num}次机会") else: print("用户名错误") print(f"你还有{3-num}次机会") else : print("系统锁定")
#for循环输出素数
for i in range(1,101): for j in range(2,i+1): if i%j == 0: if j == i: print(i) else : break
标签:username,python,代码,else,range,num,print,input From: https://www.cnblogs.com/Gavin-bk/p/18088034