sum = 0
for i in range(1, 11, 1):
a = 1
for b in range(1, i + 1):
a = a * b
sum = sum + a
print("%d" % sum)
结果即:
for i in range(1, 10):
for j in range(1, i+1):
print('{}*{}={}'.format(i, j, i*j), end=' ')
print("")
import math
for num in range(2, 101):
flag = True
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
flag = False
break
if flag is True:
print(num, end=" ")
import math
count = 0
for num in range(2, 101):
flag = True
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
flag = False
break
if flag is True:
print(num, end=" ")
count += 1
if count % 5 == 0:
print()
结果即:
for i in range(1, 5):
ii = i*100
for j in range(1, 5):
if j != i:
jj = j*10
for k in range(1, 5):
if k != j and k != i:
print(ii+jj+k, end=" ")
for i in range(1, 1001):
sum = 0
for j in range(1, i):
if i % j == 0:
sum = sum+j
if sum == i:
print(i, end=",")