-1
Could you help me with my code? I am trying to get the program to print the largest prime number the user has typed, but my program is printing the largest of ALL and not the largest prime. here is the code.
def primo(numero):
if (numero == 1):
return False
for d in range(2,(int)(numero/2)+1):
if (numero % d == 0):
return False
else:
return True
c = maior = 0
while True:
numero = int(input())
if numero == 404:
break
if primo(numero):
c += primo(numero)
else:
c -= primo(numero)
if c == 1:
maior = (numero)
else:
if (numero) > maior:
maior = (numero)
if c > 0:
print(f'{maior}')
else:
print('SEM PRIMOS')
Wouldn’t it be simpler just to make a condition that if it’s prime and higher than the value
maior
then set the number to higher? Something likeif primo(numero) and numero > maior: maior = numero
. I don’t understand why you tried to count the number of cousins informed.– Woss