❶ python中如何编程求1到100之间的素数

#!/usr/bin/python

#-*- coding:UTF-8 -*-

#求素数

list=[]

i=2

for i in range (2,100):

j=2

for j in range(2,i):

if(i%j==0):

break

else:

list.append(i)

print(list)

(1)素数编程扩展阅读:

python:for语句的使用方法

for循环的语法格式:

for i in range(n):#从数据类型中拿一个值赋值给i

print(i)#打印i

例如:

#for

for i in range (1,6,2):#从一开始到六之前每隔上2个数字

print(i)#结果为1,3,5

# ------------------------------------------------

s = ["man", "woman", "girl", "boy", "sister"]

for i in s:#列表s中的每个元素给i

print(i)

#-------------------------------------------------

for i in range(5):

print(i)#结果为:0,1,2,3,4

for循环实例:数字0,1,2组成一个百位数,并且数字不重复!

#for

for i in range(0,3):

for j in range(0,3):

for k in range(0,3):

if (i != 0) and (i != j) and (i != k) and (j != k):

print (i,j,k)