15,918,471 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 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
```

## 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.

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