[Python] checking whether a number is prime

Discussão em 'Python' iniciado por Stack, Abril 4, 2025.

  1. Stack

    Stack Membro Participativo

    i am trying to create a for loop that goes through numbers in within range and check if they are divisible. Here is my code:

    user_input = input("pick a number")

    for i in range(1, int(user_input)):
    if int(user_input) % i == 0 and i != 1 and i != int(user_input):
    print("Your number is prime")
    else:
    print("your number is not prime")


    the second condition keeps getting executed even for prime numbers. What am I doing wrong?

    Continue reading...

Compartilhe esta Página