for i in range(2, 101):
if i > 1: # Prime numbers are greater than 1
for j in range(2, i):
if (i % j) == 0:
print(i,"is a composite number")
break
else:
print(i,"is a prime number")
程序运行如下:
2 is a prime number
3 is a prime number
4 is a composite number
5 is a prime number
6 is a composite number
7 is a prime number
8 is a composite number
9 is a composite number
10 is a composite number
...
我的问题是:我们如何将合数放在同一行而质数放在一行
换句话说,如何做这样的事情:
4,6... is all composite numbers
和
2,3,5... is all prime numbers
跃然一笑
相关分类