473,563 Members | 2,326 Online

# Prime numbers

1 New Member
Hello, help me please.

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 19704
dev7060
639 Recognized Expert Contributor
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
2 New Member
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("Ente r the lower value:"))
upper = int(input("Ente r the upper value:"))
for number in range(lower,upp er+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
15 New Member
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,upp er+1):
if number>1:

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

break
else:

print(number)
Apartments for rent in Achrafieh Lebanon
Mar 12 '23 #4