15,960,623 members
1.00/5 (1 vote)
See more:
The program works but I want it to output a 0 when it finds no prime numbers ending with 1 in the given interval but it just returns an empty set.

Input
2
5

Expected Output
0

Ouput

What I have tried:

```lower_value = int(input ("Please, Enter the Lowest Range Value: "))
upper_value = int(input ("Please, Enter the Upper Range Value: "))
print ("")
for number in range (lower_value, upper_value + 1):
if number > 1:
for i in range (2, number):
if (number % i) == 0:
break
else:
if number%10==1:
print (number,end=' ')
if number=="":
print('0')```
Posted
Updated 3-Nov-22 23:40pm
Patrice T 4-Nov-22 5:02am
The code in your question is wrong.

## Solution 1

Add a counter, preset it to zero before the loop.
Inside the loop, increment t6eh counter each time you find a qualifying prime.
After the loop, check the counter and print your message.

Medidala Aditya 22BIT0503 4-Nov-22 5:03am
This is the output I get

0
0
0

The modified program

f=0
lower_value = int(input ("Please, Enter the Lowest Range Value: "))
upper_value = int(input ("Please, Enter the Upper Range Value: "))
print ("")
for number in range (lower_value, upper_value + 1):
if number > 1:
for i in range (2, number):
if (number % i) == 0:
break
else:
if number%10==1:
f=1
print (number,end=' ')
if f==0:
print('0')
OriginalGriff 4-Nov-22 5:22am
That's because your code is wrong.

Start by running it in the debugger to see exactly what it is doing while it is running:

https://docs.python.org/3/library/pdb.html

## Solution 2

Change the first three lines of the first for loop to:
Python
```for number in range (lower_value, upper_value + 1):
if number % 2 == 1: // only check odd numbers
for i in range (3, number, 2): // only divide by odd numbers from 3
```

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 60 den2k88 50 merano99 50 Andre Oosthuizen 20 Dave Kreskowiak 10
 OriginalGriff 148 Pete O'Hanlon 130 merano99 80 den2k88 50 Andre Oosthuizen 50

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900