Wap to find prime no. upto n

OUTPUT NOT AS EXPECTED

1 Like

Hey Ashita,

There are a couple of things that you need to change to get the right result.
The inner loop (the one with ‘i’) should run from 2 to int((num+1)/2+1) rather than (num/2)+1.
Take from example, num = 3, in what you have done, it would take the upper limit of the inner loop as ‘2’, the loop wouldn’t run. After making the edit that I have told you, it would have the upper limit as ‘3’, and then would give the desired result.

Also, there would be a break statement after the print statement in that last line.

Additionally,
I would suggest you to add another if statement to print the value of ‘num’ if it is 2, because that is a prime number as well.

Hope this clears the doubt.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like