visualizing the code for checking if a number is prime

70 Views Asked by At

In the below code, if we input 2, it displays it as a prime number. Can you please help me visualize how the loop works for input 2?

def prime_checker(number):
    is_prime = True
    for i in range(2, number):
        if (i % number == 0):
            is_prime = False
    if is_prime:
        print(f"The {number} is a prime number")
    else:
        print(f"The {number} is not a prime number")
number = int(input("Enter the number that you want to check: "))
prime_checker(number)

I tried to visualize it but i still have that doubt.

0

There are 0 best solutions below