1、实例源码 def showSu(): a = [2, 4, 5, 6, 7, 8, 3, 11, 13] b = 0 for i in range(0, len(a)): if a[i] > 1: for j in range(2, a[i]): if a[i] % j == 0: break else: b += 1 print(a[i]) print("素数个数:%d"%b)
# -*- coding:utf-8 -*- s = 0 for x in 列表: x = int(x) temp = 0 for x1 in range(1, x): if x % x1 == 0: temp += 1 if temp <= 1: print("素数:" + str(x)) s += 1 print("素数个数:" + str(x)