he =0
for i in range(1,21):
res = 1
for j in range(1,i+1):
res *=j
he += res #论缩进的重要性
print(he)
he =0
for i in range(1,21):
res = 1
for j in range(1,i+1):
res *=j
he += res #论缩进的重要性
print(he)
1.输出六行,每行20个*。
Raw=0
while Raw<6:
Column=0
print('\n')
Raw+=1
while Column<20:
print('*',end="")
Column+=1
2.打印99乘法口诀表
a=1
b=1
while a<=9:
print("\n")
b=1
while b<=9:
c=a*b
print(a,"*",b,"=",c,end=", ")
b+=1
a+=1
3.让用户输入一个数,判断这个数是不是素数
print("请输入一个大于1的数")
a = int(input())
b = 2
Bsu = True
while b < a:
if a % b == 0:
Bsu = False
b+=1
if Bsu == True:
print("该数字是素数")
else:
print("该数字不是素数")
4.让用户输入一个三位数,求出对应的百位数,十位数,个位数
a=int(input('请输入一个三位数: '))
Bai=int(a/100)
Shi=int((a-Bai*100)/10)
Ge=a-Bai*100-Shi*10
print("百位数为: ",Bai)
print("十位数为: ",Shi)
print("个位数为: ",Ge)
5.打印出所有的水仙花数
Num=100
while Num<=999:
a=int(Num/100)
b=int((Num-a*100)/10)
c=Num-a*100-b*10
if (a**3+b**3+c**3)==Num:
print(Num)
Num+=1
6.求8!
Num=1
res=1
while Num<=8:
res*=Num
Num+=1
print(res)
7.求1!+2!+。。。。20!
Sum=0
a=1
while a<=20:
b=1
Res=1
while b<=a:
Res*=b
b+=1
Sum+=Res
a+=1
print(Sum)