Good afternoon,
I'm developing an exercise in python , I saw that there are already some similar resolutions in the forum, but I have developed one myself and I do not understand the reason for the malfunction (only 0 is returned, be that it falls into if <2
, in which case the answer is "ERROR")
Follow the code and proposal of the exercise, thank you for the help.
Write the largest_primo function that receives an integer greater than or equal to 2 as a parameter and returns the largest prime number less than or equal to the number passed to the
Note that:
maior_primo(100) deve devolver 97 maior_primo(7) deve devolver 7
def eprimo(k):
n = 2
numero = 0
if k<2:
return "Teste: Não é possivel calcular"
else:
while n<=k:
if all(n%x!=0 for x in range(2,k)):
numero=n
n=n+1
else:
n=n+1
return numero
k=int(input("numero k:"))
print(eprimo(k))