Answer to Question #305992 in Python for sruthi

Question #305992

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.


1
Expert's answer
2022-03-04T08:34:20-0500
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS