提问
以列表形式输出500以内的素数,要求每行输出五个数 def f():a=[]
for i in range(2, 500):
for j in range(2, i):
if i % j == 0:
break
else:
a.append(i)
break
return
print(f())
C:\py\venv\Scripts\python.exe C:/py/venv/1927405141_019.py
None
Process finished with exit code 0 return a
另外缺少了2 def is_prime(num):
if num == 2:
return False
for a in range(2, num // 2 + 1):
if num % a == 0:
return True
return False
def f():
a = []
for i in range(2, 500):
if not is_prime(i):
a.append(i)
return a
res = f()
for b in range(len(res)):
if b % 5 == 0:
print()
print(res, end=' ')
prime =
for i in range(3 , 500):
n = 0
for j in range(2 , i+1):
if i % j == 0:
n = n + 1
if (j == i) and n == 1:
prime.append(i)
m = len(prime)
for x in range(0,m-4,5):
print(prime,prime,prime,prime,prime)
页:
[1]