三角形:
for i in range(0,5):
for n in range(0,5):
if i + n < 5:
print("$",end="")
else:
print("" ,end="")
print() # 比较经典的
输入行数来显示等腰三角形:
d = int(input("请输入行数:”))
for i in range(d+1):
for n in range(1,d-i+1):
print(" ",end="")
for m in range(1,2*i):
print("¥",end="")
print()
用4个数,1·2·3·4组成3位无重复的三位数
for i in range(1,5):
for n in range(1,5):
for m in range(1,5):
if i != n and n != m and m != i:
print(i,n,m)
打印水仙花数
for i in range(100,1000):
a = i % 10
b = i // 10 % 10
c = i // 100
d = a**3 + b**3 + c**3
if d == i:
print(i,end=",")
输入月份显示天数
while True;
month = input("请输入月份:")
if month =="1" or month =="3" or month =="5" or month =="7" or month =="8" or month =="10" or month =="12":
print("本月有31天")
elif month =="4" or month =="6" or month =="9" or month =="11":
print("本月有30天”)
elif month =="2":
year = input("请输入年份”)
year =int(year)
if (year % 4 == 0 and year %100 != 0) or year % 400 == 0:
print("本月有29天”)
else:
pirint("本月有28天")
else:
print("您输入有误")
tag = input("您是否要继续:" y/n)
if tag == "n":
break
print("谢谢使用") # bug不管输入什么都会继续
打印小于5,大于5时显示大于等于5终止
count = 0
while count < 5:
print(count,"小于5”)
count = count + 1
else:
print(count,"大于等于5")
输入成绩,分别显示90以上,70分到90分,60分到70分,60分以下 各有多少
a,b,c,d = 0,0,0,0
while True:
cj = input("请输入成绩:")
cj = int(cj)
if cj >= 90 and cj <= 100:
a +=1
elif cj >=70 and cj <90:
b +=1
elif cj >=60 and cj <70:
c +=1
elif cj <60 and cj >=0:
d +=1
else:
print("您输入有误:")
tag = input("您是否要继续:" y/n)
if tag == "n":
break
print("90分以上的有:",a,"人")
print("70分以上的有:",b,"人")
print("60分以上的有:",c,"人")
print("60分以下的有:",d,"人")
一个简单的登录框
print("="*30) print("欢迎进入学员管理系统V1.0") print("1. 登录") print("2. 退出") print("1. 认证") print("1. 修改密码") print("="*30) yonghu = "xjf" mima = "xjf" tag = True while True: num = int(input("请选择:")) if num == 1: while True: id = input("请输入账号:") mi = input("请输入密码:") if id == yonghu and mi == mima: print("登录成功") break else: print("账号密码不匹配:") continue elif num == 2: break elif num == 3: while True: myid = input("请输入身份证号码:") if myid.isdigit() and len(18): name = input("请输入名字:") if name.len(3): print("验证成功!") break else: print("输入错误!") continue elif num == 4: while True: a = input("请输入原密码:") if a == mima: while True: mima = input("请输入新密码:") if mima.isdigit() or mima.isalpha(): print("密码太简单了!") continue else: print("密码修改成功") break break else: print("原密码错误") continue else: print("输入的指令有误,请重新输入:") continue