1、
n
!
n!
n!
a = eval(input("输入一个要计算阶乘的数"))
n = 1
if a == 0:
n = 0
for i in range(1,a+1):
n *= i
print("{}!={}".format(a,n))
2、
1
!
+
2
!
+
3
!
?
?
?
n
!
1!+2!+3!···n!
1!+2!+3!???n!
k = eval(input("请输入计算阶乘的数值:"))
sum1 = 0
if k == 0:
sum1 = 1
for i in range(1,k+1):
t = 1
for j in range(1,i+1):
t *= j
sum1 += t
print(sum1)
3、
1
+
2
+
3
+
?
?
?
+
100
1+2+3+···+100
1+2+3+???+100
n = 0
for i in range(101):
n += i
print(n)
4、
1
?
2
+
3
?
4
+
?
?
?
99
?
100
1-2+3-4+···99-100
1?2+3?4+???99?100
n = 0
for i in range(101):
if i%2 == 0:
n -= i
else:
n += i
print(n)
5、
1
/
2
+
2
/
3
+
3
/
4
+
?
?
?
+
99
/
100
1/2+2/3+3/4+···+99/100
1/2+2/3+3/4+???+99/100
sum1 = 0
for i in range(1,100):
sum1 += i/(i+1)
print(sum1)
6、
1
/
2
+
1
/
(
2
?
3
)
+
1
/
(
3
?
4
)
+
?
?
?
+
1
/
(
99
?
100
)
1/2+1/(2*3)+1/(3*4)+···+1/(99*100)
1/2+1/(2?3)+1/(3?4)+???+1/(99?100)
sum1 = 0
for i in range(1,100):
sum1 += 1/(i*(i+1))
print(sum1)
7、
1
/
2
?
1
/
(
2
?
3
)
+
1
/
(
3
?
4
)
+
?
?
?
+
1
/
(
99
?
100
)
?
1
/
(
100
?
101
)
1/2-1/(2*3)+1/(3*4)+···+1/(99*100)-1/(100*101)
1/2?1/(2?3)+1/(3?4)+???+1/(99?100)?1/(100?101)
sum1 = 0
for i in range(1,100):
sum1 += 1/(i*(i+1))*(-1)**(i+1)
print(sum1)
8、在2-100之间寻找素数(质数)
num = []
for i in range(2,100):
for j in range(2,i):
if(i%j == 0):
break
else:
num.append(i)
print(num)
9、(*)星号矩阵
for i in range(5):
for j in range(5):
print("*",end="")
print()
10、输出如下内容输出
for i in range(4):
for i in range(1,5):
print(i,end="")
print()
11、输出如下内容输出
for i in range(1,5):
for j in range(4):
print(i,end="")
print()
12、输出如下内容输出
for i in range(1,5):
n = i
for j in range(4):
print(n,end=" ")
n += 4
print()
13、输出如下内容输出
for i in range(1,5):
if i%2==1:
n = 4*i-3
for j in range(4):
print(n,end=" ")
n += 1
print()
else:
n = i*4
for j in range(4):
print(n,end=" ")
n -= 1
print()
14、实现如下内容输出
for i in range(1,6):
n =int(i*(i-1)/2+1)
for j in range(i):
print(n,end=" ")
n += 1
print()
15、实现如下内容输出
for i in range(1,5):
n = 1
for j in range(i):
print(n,end="")
n += 1
print()
16、实现如下内容输出
for i in range(1,5):
for j in range(i):
print("*",end="")
print()
a = eval(input("请输入一个数"))
for i in range(1,a+2):
if i == 1:
print("*")
elif i == a+1:
print("* "*(a+1),end="")
else:
print("*",end="")
print(" "*(i*2-3),end="")
print("*")
17、实现如下内容输出
a = eval(input("请输入一个数"))
for i in range(1,a+1):
for j in range(i-1):
print(" ",end="")
for j in range(a-i+1):
print("*",end="")
print()
a = eval(input("请输入一个数"))
for i in range(1,a+1):
for j in range(i-1):
print(" ",end="")
if i==1 or i==a or i==a-1:
for j in range(a-i+1):
print("*",end="")
else:
print("*",end="")
print(" "*(a-i-1), end="")
print("*", end="")
print()
18、实现如下内容输出
for i in range(4,0,-1):
for j in range(i):
print("*",end="")
print()
a = eval(input("请输入一个数"))
for i in range(a,0,-1):
if i==a or i==1 or i==2:
print("*"*i,end="")
else:
print("*", end="")
print(" "*(i-2), end="")
print("*", end="")
print()
19、实现如下内容输出
for i in range(4,0,-1):
for j in range(i-1):
print(" ",end="")
for j in range(4-i+1):
print("*",end="")
print()
a=eval(input("请输入一个数"))
for i in range(a,0,-1):
for j in range(i-1):
print(" ",end="")
if i==a or i==a-1 or i==1:
print("*"*(a-i+1), end="")
else:
print("*", end="")
print(" "*(a-i-1), end="")
print("*", end="")
print()
20、实现如下内容输出
a=eval(input("请输入一个数"))
for i in range(a,0,-1):
for j in range(i-1):
print(" ",end="")
for j in range(2*a-2*i+1):
print("*",end="")
print()
a=eval(input("请输入一个数"))
for i in range(a,0,-1):
for j in range(i-1):
print(" ",end="")
if i==a :
print("*",end="")
elif i==1:
print("*"*(2*a-1),end="")
else:
print("*", end="")
print(" "*(a*2-i*2-1), end="")
print("*", end="")
print()
21、实现棱形
链接: 实心和空心棱形.
|