472,121 Members | 1,506 Online

# Prime numbers

Write a function: User enters natural numbers A and B (A <B). The function prints all prime numbers separated by a space on the segment [A, B]
Nov 25 '21 #1
3 17984
dev7060
624 Expert 512MB
Write a function: User enters natural numbers A and B (A <B). The function prints all prime numbers separated by a space on the segment [A, B]
What have you done so far?
Dec 1 '21 #2
sumairaanwar
1 Bit
yes you can use a foe loop and in if condition use if number is divisible by 2 don't print but if number is not divisible y 2 print it

lower = int(input("Enter the lower value:"))
upper = int(input("Enter the upper value:"))
for number in range(lower,upper+1):
if number>1:
for i in range(2,number):
if (number%i)==0:
break
else:
print(number)
code pro zone
Feb 17 '22 #3
zermasroor
6 Nibble
you can use if else statements to check the given condition of numbers this if will check all the vales one by one if you want to print those values you can different print statements separately for prime numbers or even numbers
for number in range(lower,upper+1):
if number>1:

for i in range(2,number):
if (number%i)==0:

break
else:

print(number)
Apartments for rent in Achrafieh Lebanon
1 Week Ago #4