The problem is you are iterating from 2 till that number. So it goes into the loop, number is 2
, and 65 % 2 != 0
. Hence It returns 'This is a prime number'
. Instead try this:
def prime(num):
if num == 1 or num == 0:
return 'This is not a prime number'
for number in range(2, num):
if num % number == 0 :
return 'This is not a prime number'
return 'This is a prime number'
What this does is it keeps looping until remainder is 0. If the remainder is never 0, it returns 'This is a prime number'.
P.S. 2 is a prime number.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…