0
I've found a question in challenges, that I think the answer is wrong, but not sure
I've copied the code just for making the question. In this code, the answer for the challenge was False, but, wouldn't it be True? https://code.sololearn.com/ciphXWUlKZf4/?ref=app
17 ответов
+ 6
Thanks.
Yea, the question is right but the code is misleading.
It stops after checking if it is divisible by 2, by returning false or true. True if its divisible by 2, false otherwise.
So, it isn't even really a prime checker. It's more of an even number checker.
That looks to me like a fine question except for the fact that it disguises itself as a prime checker. Idk whether or not it's actually a fair question. Would need more opinions.
+ 4
Maybe to imgur? Then post the link. If that's to much of a hastle, don't worry about it.
The problem with how this code is, its written so that it returns a value right after the if statements are evaluated.
So, it basically only ever tests if the number is divisible by 2. Everything else is false. If you plug in 7, which is a prime, it comes as false. While 8 is true.
So the code is written incorrectly.
However, the answer of the challenge is still right for what was written in the code.
+ 4
Once the function returns something it stops.
As you said "I can see in the for loop 21 % 2 == 0, returns false"..
So the for loop never goes to check 21 % 3. It returns false right after checking 2, once returned it's done.
+ 4
Yea the loop won't keep returning more things.
I still think this is a bad question, but it isn't wrong on the answer.
+ 3
Without reading a lot of the actual code, the function is named "is_Prime".
So, I assume it returns true if the number is a prime.
Assuming the function properly determines if the number is a prime, 21 is not a prime.
7 * 3 = 21.
So, false.
The output in that code also gave false btw.
+ 3
Strange, can I see a screen shot of the challenge question by any chance?
+ 1
I think it could be fixed like this:
https://code.sololearn.com/cY4Uqnop4Cn4/?ref=app
+ 1
Thanks, I'm not English so I don't understand some sentences. But yes, the answer is correct though it is not a very well functional code
0
I think he would have to change the positions of True and False
0
I though so, and answered false because 21 is not a prime number. But the code 'says' in words: if the number is divisible by another, it is prime. That's not true
0
Sure, how can I upload a picture?
0
Okay, http://imgur.com/JHnM8A5
0
In that picture you can see I answered correctly because I though the code was written correctly. 21 is not prime, so answer should be False. But. Reading the code I can see in the for loop: if 21 % 2 == 0 (which is false), ok, it returns false, but then it checks if 21 % 3 == 0 (true) so it should print True. 21 is not prime, but it prints True. What? It also return True or False every time in the loop. So it'll print:
False
True
False
False
False
True
False
etc...
0
Oh, really? So if in the middle of a loop I put return something, it stops right after returning it?
0
Oh
0
Okay
0
Now I understand it