From what I understand you want to implement a code that is able to verify if a certain number is cousin.
According to the definition, prime numbers sane: natural numbers greater than 1 that have only two divisors, i.e., are divisible by 1 and by itself.
One of the correct ways to verify that a certain number is prime is by using the following code::
def verifica_primo(n):
i = 1
cont = 0
while i <= n:
if n % i == 0:
cont += 1
i += 1
if cont != 2:
return False
else:
return True
num = int(input('Digite um número inteiro: '))
print(verifica_primo(num))
Note that when we execute this code we receive the following message: Digite um número inteiro:
. Right now we must enter an integer number and press enter
. Then the variable value num
is passed as parameter n
for the function verifica_primo(n)
. Getting there, the block while
shall traverse the closed interval [i, n], where i
starts with the value 1
going to the maximum value n
. With the help of 1st block if will be verified whether i
is divider of n
. If positive, the unit will be accumulated in the variable cont
. Subsequently, the 2nd block if check the value of the variable cont
. If its value is other than 2, the function will return False and otherwise the function will return True. In other words, if the number typed is prime, the output will be True
, otherwise the output will be False
.
I notice that your question has a lot to do with your previous question.
– Victor Stafusa
Your algorithm does not check if the number is prime. The messages in your code are wrong. As Victor Stafusa showed you just check if
numero
is or is not divisible byx
.– anonimo