Ad
  • Default User Avatar

    I will get an error expected:<1.57[]> but was:<1.57[
    ]>
    What is the problem here?

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    @FArekkusu, I know the algorithm is correct, I just wanted to show which iterations are unnecessary without giving any hints. And by explaining me the exact mechanical process the user must've a thought: why am I repeating things and doing uncessary work, which is often missed when algorithm is not thought with sufficient amount of patience.

  • Custom User Avatar

    It is enough to check up to num / 2

    Why exactly up to num/2? It's also too much. Let's take a biggenr umber, for example 101. Do you really need to check up to 101 % 50? Hint: no, you don't.

  • Default User Avatar

    so the problem is solved .thank you.

  • Custom User Avatar

    how will you verify whether 17 is a prime number?

    The algorithm is correct. The only problem is that it does a lot more work than required, as hinted in the @hobovsky's comment.

  • Custom User Avatar

    Do you really nee to check 17 % 16?

  • Default User Avatar

    okey, first 17 is greater than 1 so "else" will run.Then in the for loop, respectively the number of 2,3,4,5,6....16 will be '%' into 'num'.None of these numbers can % == 0 because 17%2= 1, 17%3=2 , ...17 % 16= 1 .so else will run.finally else is return True.so 17 is prime.

  • Custom User Avatar

    how will you verify whether 17 is a prime number?
    (tell me the exact mechanical process)

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution