Read the Input into a variable.
Now using the loop iterate in range 1 to input.
Again read the second input into the variable.
Now take the count to assign the value 0 to it.
Using loop condition iterate from range 1 to second input.
using the if condition checks the condition that the second input is divisible by number then increment the count.
If the count is equal to 2
print the number and break from the loop.
Example:
2
4
7
5
the output will be 2 it is the first prime number.
num=-1
while(num<0):
num = int(input("Inputa a number (>0): "))
Count=0
for r in range(1,num):
Flag=1
for c in range(2,r):
if(r%c==0):
Flag=0
if(Flag==1):
Count=Count+1
print(r)
print("Total Count = ",Count)
Comments
Leave a comment