Print prime numbers in range 0-N

Asked

Viewed 82 times

-1

Basically the program must check and display all prime numbers up to the entered value. I have already made a code that checks if it is prime or not (the check has to be done by a function), but I do not know how to display the numbers until the entered value.

def primo(numero):
    if numero != 0 & numero != 1:
        if numero > 3:
            for i in range(2, numero):
                if numero % i == 0:
                    return False
        return True
    return False
num = int(input("Digite um numero:"))
print("É primo" if primo(num) else "Não é primo")
  • 2

    From a look https://answall.com/search?q=%5Bpython%5D+primo and see if it helps.

  • 1

    Thanks guys I got.

1 answer

0

Good morning dear friend. From what I understand, you can use a for along with a range for that reason:

max = int(input('Digite um número: '))
for número_atual in range(max):
    print("É primo" if primo(num) else "Não é primo")

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.