sm = 0
for i in range(1, 101):
sm = sm + i
print(sm)
运行结果: 5050
res = 1
for i in range(2, 7):
res = res * i
print(res)
运行结果: 720
res = 0
for i in range(0, 101, 2):
res = res + i
print(res)
运行结果: 2550
coun = 0
for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
coun=coun+1
print(coun)
运行结果: 6
*
* *
* * *
* * * *
* * * * *
for i in range(1, 6):
print('* ' * i)
for i in range(1, 10):
for j in range(1, i + 1):
print('%d * %d = %d'%(j, i, (j * i)), end='\t')
print('')
import math
n = int(input('请输入一个数:'))
tag = 0
for i in range(2, int(math.sqrt(n))+1):
if n%i==0:
tag = 1
if tag == 0:
print('是质数')
else:
print('不是质数')
import math
coun = 0
tag = 0
for i in range(2, 100000):
for j in range(2, int(math.sqrt(i)) + 1):
if i % j == 0:
tag = 1
if tag == 0:
coun = coun + 1
tag = 0
print(coun)
运行结果: 9592