Check prime number or not

when i am running this code its showing right output even for negative numbers but test cases are not getting passed.why?

and how we will came to know whether to check for negative no or not for test cases.as in the previous questions it was not asked to check for it.

hello @lovely
image

a) u need to print exaclty in this format of text.
b) check constraints there they have clearly mentioned that n > 2

ya they have mentioned the constraints but my doubt was that in some previous questions we didnt consider the constraints while writing code still code test cases run .how?

ur code might be working for all cases.
btw given constrainst will always be followed in the given test cases u dont have to explicity handle it in ur code

so is it good to write code according to the constraints like it?or whether depends on question

u can always assume that metioned constraint will always be followed.
so no need to handle them explicity as it make ur bit messy