PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""__ALL COMPOSITE & PRIME NUMBERS WITHIN GIVEN RANGE__"""
""" INPUT 2 NUMBERS LIKE THIS==> 50,100 """
x=input("Determine which numbers within range are composite or prime\nfor example 50,100: ")
print(x)
x=x.split(",")
x[0],x[1]=int(x[0]),int(x[1])
c,y,z=[],min(x),max(x)
while len(x)!=2 or y<0 or z<0 or y==z:
x=input("Enter 2 different numbers separated by 1 comma & both >= 0\nfor example 50,100 :")
if y==0 and z==1:
print("\n0 and 1 are neither prime nor composite numbers")
elif y==0 and z==2:
print("\n0 and 1 are neither prime nor composite numbers\n2 is the only even prime number")
elif y==1 and z==2:
print("\n1 is neither prime nor composite number\n2 is the only even prime number")
elif y<=2 and z>2:
for i in range(3,z+1):
for j in range(2,i):
if i%j==0:
c.append(i)
c=sorted(list(set(c)))
p=[a for a in range(2,z+1) if a not in c]
print("\n"+str(len(c))+" Composite number(s) within given range:\n"+str(c)+"\n\n"+str(len(p))+" Prime number(s) within given range:\n"+str(p))
else:
for i in range(y,z+1):
for j in range(2,i):
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run